Skip to content
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

String rindex does not work properly with matchdata #1688

Closed
zhaohanweng opened this issue May 9, 2014 · 0 comments
Closed

String rindex does not work properly with matchdata #1688

zhaohanweng opened this issue May 9, 2014 · 0 comments
Assignees
Milestone

Comments

@zhaohanweng
Copy link

@zhaohanweng zhaohanweng commented May 9, 2014

Case 1: message ends with the matched word

message = "I love this new status update"
=> "I love this new status update"
matched_string = message.match(/status update/)[0]
=> "status update"
message.rindex(matched_string)
=> 16
message.rindex("status update")
=> 16

Case 2: message does not end with the matched word

message = "I love this new status update..."
=> "I love this new status update..."
matched_string = message.match(/status update/)[0]
=> "status update"
message.rindex(matched_string)
=> 19
message.rindex("status update")
=> 16

I am not sure why this would happen, matched_string is just a string, the value is the same "status update", how does it pickup the ... from the end of the message.

I tried in MRI ruby 1.9.3-p545 and 2.1.1, the issue does not occur.

Also I find if I do message.rindex(matched_string.tr("", ""))), the result will be 16.
But

matched_string.to_java_bytes
=> byte[115, 116, 97, 116, 117, 115, 32, 117, 112, 100, 97, 116, 101]@543c5bbd
"status update".to_java_bytes
=> byte[115, 116, 97, 116, 117, 115, 32, 117, 112, 100, 97, 116, 101]@46ab007f
And
matched_string.bytesize
=> 13
"status update".bytesize
=> 13

I don't see any special characters in the matched_string.

@atambo atambo added this to the JRuby 1.7.13 milestone May 24, 2014
@atambo atambo self-assigned this May 24, 2014
@atambo atambo closed this in 5303e9a 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants