Skip to content

Audit excluded tests on JRuby and address differences #1123

Open

Description

@headius

Several tests still explicitly exclude JRuby and do not run against the Java extension. We should reexamine these and fix as many differences with the C extension as possible.

$ git grep -e "RUBY_ENGINE == [\"']jruby" test 
test/json/json_generator_test.rb:    if RUBY_ENGINE == "jruby"
test/json/json_minefield_parser_test.rb:  if RUBY_ENGINE == 'jruby'
test/json/json_parser_test.rb:    unless RUBY_ENGINE == 'jruby'
test/json/json_parser_test.rb:    omit "JRuby errors don't contain positions" if RUBY_ENGINE == "jruby"
test/json/json_parser_test.rb:    omit "JRuby errors don't contain positions" if RUBY_ENGINE == "jruby"
test/json/json_parser_test.rb:    omit "JRuby string decoding errors don't contain positions" if RUBY_ENGINE == "jruby"
test/json/resumable_parser_test.rb:    omit "JRuby not supported" if RUBY_ENGINE == "jruby"

Some of these may be valid but most involve changes made to the C extension that were never ported to the Java extension. That last one excludes all of the ResumableParser tests because that entire feature is missing from the Java extension.

See #1122 for one example of a latent bug hidden by these masks.

Activity

  1. headius commented on Nov 4, 2026

    @headius
    ContributorAuthor

    Some of these are due to #138.

  2. wtn commented on Nov 14, 2026

    @wtn
    Contributor

    Another JRuby/Java extension difference from the C extension, in script_safe mode:

    isUnsafeScriptTag in java/src/json/ext/StringEncoder.java reads ptrBytes[pos], but its callers in StringEncoder and StringEncoderAsciiOnly use ptrBytes[ptr + pos]. For a substring at a non-zero offset, the Java extension checks the wrong bytes:

    JSON.generate(("a" * 100 + "</script>")[100..], script_safe: true)
    # JRuby: leaves "<" unescaped: "</script>"
    # C extension: escapes "<" as \u003c: "\\u003c/script>"

    The Java helper also reads ptrBytes[pos] after pos++ without a length check, so a string ending in < reads past its end. The C extension checks the length first.

  3. byroot commented on Nov 15, 2026

    @byroot
    Member

    Urgh, that ptr+pos is very error prone. Fixed in #1147, but I think we should refactor that code: #1148

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