Repository navigation
Conversation
A range whose ends are both single ASCII characters said it included
its end even when the range was empty, so ("z".."a").include?("a")
returned true while to_a was empty and cover?("a") returned false.
RubyString.includeRange compares the characters directly for this kind
of range instead of iterating, and its last check returned true when
the value equaled the end without checking that the begin isn't after
the end. Add that check, so include? and member? agree with to_a, each
and cover?.
This ports ruby/ruby#19313 from CRuby, which
fixes https://bugs.ruby-lang.org/issues/22432, including its tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ports ruby/ruby#19313 from CRuby, which fixes Bug #22432.
A range whose ends are both single ASCII characters says it includes its end even when the range is empty:
RubyString.includeRangehas the same shortcut as CRuby'srb_str_include_range_p: for this kind of range, it compares the characters directly instead of iterating. Its last check returns true when the value equals the end, without checking that the begin is not after the end. This adds that check, soinclude?andmember?agree withto_a,eachandcover?. JRuby 9.4.15.0, 10.0.7.0 and 10.1.2.0 all have the bug.The tests are the ones from the CRuby PR, added to
test/mri/ruby/test_range.rb. The new assertions fail on 10.1.2.0, and with this change all oftest_range.rband the Range specs in ruby/spec pass.The CRuby fix has already been backported to Ruby 3.4, is marked for backport to 4.0, and will be in Ruby 4.1, so it should be safe to port to JRuby now. It might be worth backporting to JRuby 10.0 and 9.4, too. Please let me know if you want me to open backport PRs for those older releases as well.