ruby / ruby/psych

yaml parsing is wrong when key's value has leading colon

Open
#669 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
597
Forks
223
Avg merge
11h 23m
Merged PRs (30d)
3

Description

replication steps:

ruby -ryaml -e "a = YAML.load('servers: ::ffff:10.10.10.1'); puts a; puts a['servers']"
{"servers"=>:":ffff:10.10.10.1"}
:ffff:10.10.10.1

expected:

{"servers"=>"::ffff:10.10.10.1"}
::ffff:10.10.10.1

actual result:

{"servers"=>:":ffff:10.10.10.1"}
:ffff:10.10.10.1

Environment:

ruby --version
ruby 2.7.0p0

gem list yaml 
yaml (0.3.0)

Python yaml works as expected:

python3.9 -c 'import yaml; a=yaml.safe_load("servers: ::ffff:10.10.10.1"); print(a); print(a["servers"]);'
{'servers': '::ffff:10.10.10.1'}
::ffff:10.10.10.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the result with the Ruby YAML.load command shown in the issue, then trace how that input is handled by Psych and its libyaml wrapper. The fix is done when the leading double colon remains part of the scalar value and the displayed hash and value match the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.