Project

General

Profile

Actions

Bug #22492

closed

String#rindex misses a match with a leading .* in multiline mode

Bug #22492: String#rindex misses a match with a leading .* in multiline mode

Added by mame (Yusuke Endoh) 14 days ago. Updated about 5 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127294]

Description

String#rindex with a regexp starting with .* in multiline mode returns nil even when there is a match.

"xab".rindex(/.*b/m) #=> nil (expected: 2)
"xab".rindex(/.*b/)  #=> 2

@make_now_just (Hiroya Fujinami) found this and wrote the fix.

Updated by mame (Yusuke Endoh) 14 days ago Actions #2

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED

Updated by make_now_just (Hiroya Fujinami) 7 days ago Actions #3

  • Status changed from Open to Closed

Applied in changeset git|d55b67dfa3c1f94a4855381b400da7aa987bb5be.


Do not use the leading .* shortcut in a backward search

A match at an earlier position does not imply one at the start position, so String#rindex with /.*.../m missed matches.

[Bug #22492]

Updated by k0kubun (Takashi Kokubun) about 5 hours ago Actions #4 [ruby-core:127513]

  • Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE
Actions

Also available in: PDF Atom