Project

General

Profile

Actions

Bug #17120

closed

String#start_with? return wrong result for Regexp patterns containing /\K/

Added by hanazuki (Kasumi Hanazuki) over 3 years ago. Updated almost 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.8.0dev (2020-08-13T01:14:20Z master 69b5241c36) [x86_64-linux]
[ruby-core:99580]

Description

String#start_with? unexpectedly reports true when the pattern Regexp contains /\K/ (lookbehind) operator and the lookbehind pattern matches the beginning of self.

"hello".start_with?(/h\Ke/)  # => true (unexpected)

In this example, /h\Ke/ matches "hello", but it's not considered as a match at the beginning of the string by the other Regexp operations (e.g. $~.begin(0) == 1).

Actions

Also available in: Atom PDF

Like0
Like0Like0