ruby / ruby/psych

Different behavior when parsing tabs in between JRuby and MRI Ruby versions

Open
#462 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

In certain cases, MRI Ruby Psych and JRuby Psych will return different results for the same string, even if both of them are in the same version. For example, this happens when parsing in MRI Ruby:

Psych.load("location:\tCalifornia")
irb(main):002:0> Psych.load("location:\tCalifornia")
=> {"location"=>"California"}

Meanwhile, JRuby throws an exception:

irb(main):008:0> Psych.load("location:\tCalifornia")
Traceback (most recent call last):
       10: from /Users/cplanas/.rbenv/versions/jruby-9.2.9.0/bin/irb:13:in `<main>'
        9: from org/jruby/RubyKernel.java:1193:in `catch'
        8: from org/jruby/RubyKernel.java:1193:in `catch'
        7: from org/jruby/RubyKernel.java:1446:in `loop'
        6: from org/jruby/RubyKernel.java:1052:in `eval'
        5: from (irb):8:in `evaluate'
        4: from /Users/cplanas/.rbenv/versions/jruby-9.2.9.0/lib/ruby/gems/shared/gems/psych-3.2.0-java/lib/psych.rb:277:in `load'
        3: from /Users/cplanas/.rbenv/versions/jruby-9.2.9.0/lib/ruby/gems/shared/gems/psych-3.2.0-java/lib/psych.rb:388:in `parse'
        2: from /Users/cplanas/.rbenv/versions/jruby-9.2.9.0/lib/ruby/gems/shared/gems/psych-3.2.0-java/lib/psych.rb:454:in `parse_stream'
        1: from org/jruby/ext/psych/PsychParser.java:246:in `parse'
Psych::SyntaxError ((<unknown>): found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation) while scanning for the next token at line 1 column 10)

I tested this in version3.2.0.

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 discrepancy with Psych.load("location:\tCalifornia") on MRI Ruby and JRuby, then inspect psych.rb and the org/jruby/ext/psych/PsychParser.java path shown in the trace. Compare the parser behavior and add a regression test demonstrating the expected result across both runtimes.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.