Skip to content

String#rindex should handle matchdata strings#1714

Merged
enebo merged 1 commit intojruby:jruby-1_7from
atambo:rindex_with_matchdata
Jun 14, 2014
Merged

String#rindex should handle matchdata strings#1714
enebo merged 1 commit intojruby:jruby-1_7from
atambo:rindex_with_matchdata

Conversation

@atambo
Copy link
Member

@atambo atambo commented May 24, 2014

A string extracted from a matchdata object shares the same
byte array as the string it was matched against. When doing a
rindex between a string from a matchdata and the string the matchdata
was matched against the same byte array is passed into ByteList.memcmp
which will always return 0 as ByteList.memcmp just checks for equality
of the byte arrays.

I fix this by passing bytes() instead getUnsafeBytes() into the
ByteList.memcmp method so that the byte arrays are different.

Fixes #1688

A string extracted from a matchdata object shares the same
byte array as the string it was matched against. When doing a
rindex between a string from a matchdata and the string the matchdata
was matched against the same byte array is passed into ByteList.memcmp
which will always return 0 as ByteList.memcmp just checks for equality
of the byte arrays.

I fix this by passing bytes() instead getUnsafeBytes() into the
ByteList.memcmp method so that the byte arrays are different.

Fixes jruby#1688
enebo added a commit that referenced this pull request Jun 14, 2014
String#rindex should handle matchdata strings
@enebo enebo merged commit 5a36c57 into jruby:jruby-1_7 Jun 14, 2014
@enebo enebo added this to the JRuby 1.7.13 milestone Jun 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants