Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshalled data fails validation with several online validators #35

Open
andy-miracl opened this issue Aug 20, 2018 · 0 comments
Open

Comments

@andy-miracl
Copy link

andy-miracl commented Aug 20, 2018

When I have a long string value that also contains a single quote, the marshalled yaml fails validation with a number of online yaml validators.

e.g. the third example generated by this code fails in :

https://codebeautify.org/yaml-validator
https://onlineyamltools.com/validate-yaml

package main

import (
	"fmt"
	"github.com/ghodss/yaml"
)

type X struct {
	Y string
}

func main() {

	// single-quotes are ok
	b, _ := yaml.Marshal(X{Y: `'`})
	fmt.Println(string(b))

	// new lines with single quotes are ok
	b, _ = yaml.Marshal(X{Y: `'\n`})
	fmt.Println(string(b))

	// single quotes with wrapped lines causes failed validation
	b, _ = yaml.Marshal(X{Y: `' 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789`})
	fmt.Println(string(b))

The above code outputs :

"Y": ''''

"Y": '''\n'

"Y": ''' 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
  123456789'

I appreciate that the yaml marshaller outputs valid yaml, but the fact that it fails in some of the most popular online validators is a bit of a frustration.

Is there anything that could be done to tackle this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant