New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modification check on String#chomp! method with default separator #5041

Merged
merged 1 commit into from Feb 13, 2018

Conversation

Projects
None yet
2 participants
@nomadium
Contributor

nomadium commented Feb 13, 2018

When working on #5039 I noticed one of String tests on #chomp! method was not passing:

s = S("").freeze
assert_raise_with_message(FrozenError, /frozen/) {s.chomp!}

https://github.com/jruby/jruby/blob/ruby-2.5/test/mri/ruby/test_string.rb#L445

After looking closely, I learned that MRI folks introduced this test on ruby/ruby@80aa1e6.

I'm proposing this change since this is a difference between MRI and JRuby.

Behavior before applying this change:

miguel@alice:~/jruby/upstream/jruby$ PATH=$PWD/bin:$PATH jirb
irb(main):001:0> s = String.new("").freeze
=> ""
irb(main):002:0> s.chomp!
=> nil
irb(main):003:0>

Behavior after applying this change:

miguel@alice:~/jruby/upstream/jruby$ PATH=$PWD/bin:$PATH jirb
irb(main):001:0> s = String.new("").freeze
=> ""
irb(main):002:0> s.chomp!
RuntimeError: can't modify frozen String
        from org/jruby/RubyString.java:4286:in `chomp!'
        from (irb):2:in `<eval>'
        from org/jruby/RubyKernel.java:995:in `eval'
        from org/jruby/RubyKernel.java:1316:in `loop'
        from org/jruby/RubyKernel.java:1138:in `catch'
        from org/jruby/RubyKernel.java:1138:in `catch'
        from /home/miguel/jruby/upstream/jruby/bin/jirb:13:in `<main>'
irb(main):003:0> 

MRI behavior:

miguel@alice:~/jruby/upstream/jruby$ irb2.5
irb(main):001:0> s = String.new("").freeze
=> ""
irb(main):002:0> s.chomp!
Traceback (most recent call last):
        3: from /usr/bin/irb2.5:11:in `<main>'
        2: from (irb):2
        1: from (irb):2:in `chomp!'
FrozenError (can't modify frozen String)
irb(main):003:0> 

This change should be applied to master as well.

@enebo enebo added this to the JRuby 9.1.16.0 milestone Feb 13, 2018

@enebo enebo merged commit ba92c73 into jruby:jruby-9.1 Feb 13, 2018

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@nomadium nomadium deleted the nomadium:raise-error-on-changes-to-frozen-empty-string branch Feb 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment