Skip to content

Conversation

calebstewart
Copy link

@calebstewart calebstewart commented Aug 5, 2025

This PR adds an option to ScalarScanner to disable the parsing of values containing a leading colon as symbols. This is unexpected behavior when compared with other YAML parsers and when compared with the YAML specification, as symbols are not a concept defined by YAML. I do not expect that we can change the default here as that would break backwards compatibility, so this PR maintains current behavior by leaving the default as parse_symbols: true, but exposes a way that users can modify the behavior in order to match what is expected based on the YAML specification.

The option is added to the load() family of methods at the top level as well as to the ToRuby visitor and the associated node to_ruby() method. In all instances, the default value of the new parse_symbols parameter is true in order to maintain backwards-compatible behavior. Passing a value of false for this parameter will result in values with leading colons being treated as regular strings.

@calebstewart
Copy link
Author

This PR was created in response to #669. For a concrete example of this functionality, I'll use an equivalent example from that original issue:

irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> a = YAML.load('servers: ::ffff:10.10.10.1')
=> {"servers"=>:":ffff:10.10.10.1"}
irb(main):003:0> b = YAML.load('servers: ::ffff:10.10.10.1', parse_symbols: false)
=> {"servers"=>"::ffff:10.10.10.1"}
irb(main):004:0>

@calebstewart calebstewart marked this pull request as ready for review August 5, 2025 02:46
@calebstewart calebstewart changed the title Add option to disable symbol parsing for ScalarParser Add option to disable symbol parsing for ScalarScanner Aug 5, 2025
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

Successfully merging this pull request may close these issues.

1 participant