ruby / ruby/psych

Nil tag with implicit: false raises error on SnakeYAML

Open
#500 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The following line, when reached by the tests from #475, triggers SnakeYAML to raise an error:

https://github.com/ruby/psych/blob/546154ddb71b125794c5eed36817ad27ac373dd5/lib/psych/visitors/yaml_tree.rb#L520

The error:

RuntimeError: org.yaml.snakeyaml.emitter.EmitterException: tag is not specified
                      scalar at org/jruby/ext/psych/PsychEmitter.java:206
    visit_Psych_Nodes_Scalar at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/emitter.rb:32
                       visit at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:30
                      accept at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:6
   visit_Psych_Nodes_Mapping at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/emitter.rb:43
                        each at org/jruby/RubyArray.java:1864
   visit_Psych_Nodes_Mapping at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/emitter.rb:43
                       visit at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:30
                      accept at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:6
  visit_Psych_Nodes_Document at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/emitter.rb:27
                        each at org/jruby/RubyArray.java:1864
  visit_Psych_Nodes_Document at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/emitter.rb:27
                       visit at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:30
                      accept at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:6
    visit_Psych_Nodes_Stream at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/emitter.rb:21
                        each at org/jruby/RubyArray.java:1864
    visit_Psych_Nodes_Stream at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/emitter.rb:21
                       visit at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:30
                      accept at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/visitors/visitor.rb:6
                        yaml at /Users/headius/projects/jruby/lib/ruby/stdlib/psych/nodes/node.rb:61
                        dump at /Users/headius/projects/jruby/lib/ruby/stdlib/psych.rb:515
                      <main> at blah.rb:13

As far as I can tell, the issue is that the tag is nil and implicit is false, which is prohibited in SnakeYAML for a mapping.

This is somewhat outside my understanding of YAML and I am not sure whether this constitutes an improper behavioral difference in SnakeYAML or not.

The implicit value comes from the default @implicit of Coder, and is never set to true in the logic hit by the tests mentioned above. As it stands I do not know how to reconcile the values being passed in with the SnakeYAML hard error.

This leads to the remaining failures in https://github.com/jruby/jruby/pull/6680, which I will exclude to proceed with the Psych update.

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

Start at lib/psych/visitors/yaml_tree.rb around line 520 and trace the nil tag and implicit value into the emitter, including org/jruby/ext/psych/PsychEmitter.java. Reproduce the tests from #475 or the remaining failures in JRuby PR #6680, then verify that dumping the affected mapping no longer triggers SnakeYAML's tag error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, ruby
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.