Coder Social home page Coder Social logo

"y" argument not parsed about yaml HOT 6 CLOSED

ghodss avatar ghodss commented on August 28, 2024
"y" argument not parsed

from yaml.

Comments (6)

pavel-georgiev avatar pavel-georgiev commented on August 28, 2024

The example above prints {10 0} instead of {10 20}

from yaml.

lwalen avatar lwalen commented on August 28, 2024

Confusingly, it looks like this is part of YAML: http://yaml.org/type/bool.html. From the linked page, we see that any key or value that matches the following pattern is considered a boolean:

y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF

This is reflected in this project here, where the key is changed to the string "true". It actually continues marshaling the value too, so if your struct had a Y int json:"true"`` or True int field, its value would be 20.

To get around this, you can quote the y in your YAML. Both single and double quotes seemed to work fine.

from yaml.

leokalev avatar leokalev commented on August 28, 2024

Sorry to butt in - I hit this issue as well. The above-mentioned "boolean pattern" is defined only in yaml-1.1 - and is marked as a draft. The current specification (yaml 1.2: http://www.yaml.org/spec/1.2/spec.html) has none of this - and the overview explicitly states that this has been removed (along with other "implicit typing rules"). BTW, current YAML parsers in other languages (e.g., Python) don't do this, either. IMO, this "feature" should be removed.

from yaml.

pnickolov avatar pnickolov commented on August 28, 2024

👍

@lwalen, thanks for the workaround - it does help. Still, things break if we have to parse externally provided files (e.g., ones generated by humans, pythons or other non-Go creatures) rather than yaml files specially crafted to work around this issue

If the old behavior is desirable for backward compatibility (unlikely), the old behavior can be preserved through an option. Considering that the latest YAML spec (1.2, see @snarfbeest comment) does not require/allow for this behavior, I would propose the default to be off (i.e., compliant with the latest spec); if we really must keep this behavior by default, it will still be better to have the proper parsing to be available even if we have to request it explicitly.

I do love this package otherwise!

from yaml.

ghodss avatar ghodss commented on August 28, 2024

Unfortunately, this behavior is controlled by the go-yaml package that this package depends on - this package doesn't parse out what a boolean is, it just trusts go-yaml to tell it which values are booleans and uses that derived information. If you'd like go-yaml to expose an option to change its behavior, you can chime in on this PR here go-yaml/yaml#222 ... if they expose the option I'd be happy to utilize it in my library as well.

from yaml.

ghodss avatar ghodss commented on August 28, 2024

Closing for now since there is no action unless go-yaml exposes an option.

from yaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.