Skip to content

Strings that could be interpreted as sexagesimal should always be emitted quoted #387

Open

Description

@alexjfisher

Not doing so causes parsers that follow the yaml 1.1 spec (crazy though it might be), to load certain unquoted mac addresses as integers.

IMO #265 wasn't actually a bug. It was following the 1.1 spec. (To make things more complicated, sexagesimal was dropped from yaml in the 1.2 spec)

Ruby 2.5 and 2.6 emit mac addresses, (but not shorter strings it thinks are more likely to be sexagesimal), unquoted.

2.6.0 :002 > '52:54:00:44:49:56'.to_yaml
 => "--- 52:54:00:44:49:56\n...\n" 
2.6.0 :003 > '44:49:56'.to_yaml
 => "--- '44:49:56'\n"

ruby < 2.5 then parse them as integers.

2.4.5 :006 >   YAML.load('macaddress: 52:54:00:44:49:56')
 => {"macaddress"=>12465480}

Here is an actual example of where the change in handling of sexagesimal has been a problem.

Activity

  1. alexjfisher commented on Aug 13, 2020

    @alexjfisher
    Author

    Another example. https://community.theforeman.org/t/custom-facts-in-foreman/20036/3

    The scsi-id string is not being quoted when output. Older versions of ruby are thinking it's an int.

  2. alexjfisher commented on Aug 13, 2020

    @alexjfisher
    Author

    @tenderlove Any chance this could be looked at? It's causing real problems for users consuming yaml with other implementations.

    4ae7a3e has broken conformance to yaml 1.1

  3. alexjfisher commented on Aug 13, 2020

    @alexjfisher
    Author

    FWIW, the implementation before the change was broken too (but possibly not noticed by anyone as it's a daft feature of the spec)

    eg in ruby 2.1, two different values being loaded as the same int

    2.1.9 :001 > require 'yaml'
     => true 
    2.1.9 :002 > YAML.load("---\na: 1:0:0:0")
     => {"a"=>3600} 
    2.1.9 :003 > YAML.load("---\na: 1:0:0")
     => {"a"=>3600}
    

    Compare to python

    Python 2.7.17 (default, Jul 20 2020, 15:37:01) 
    [GCC 7.5.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import yaml
    >>> yaml.safe_load("---\na: 1:0:0:0")
    {'a': 216000}
    
    Python 3.6.9 (default, Jul 17 2020, 12:50:27) 
    [GCC 8.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import yaml
    >>> yaml.safe_load("---\na: 1:0:0:0")
    {'a': 216000}
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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