Skip to content

JSONToYAML wrong yaml quotation of a string with ' #' sequence #140

@nbykov0

Description

@nbykov0

The function puts too many quotes in the yaml output if such a sequence appears in a quoted json string.

I've used such a code block to reproduce the issue:

package main
import (
	"fmt"
	"sigs.k8s.io/yaml"
)

func main() {
	j := []byte(`{"example": "OMG my ' #' is messed"}`)
	y, _ := yaml.JSONToYAML(j)
	fmt.Println(string(y))
}

Output:
example: 'OMG my '' #'' is messed'

Example of a correct behaviour:

j := []byte(`{"example": "OMG my 'a#' is messed"}`)

Output:
example: OMG my 'a#' is messed

Reproduces even if the quoted string contains any other chars around the ' #' sequence.
I can also see the bug in kubectl output and during helm rendering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions