Project

General

Profile

Actions

Feature #18838

closed

Avoid swallowing regexp escapes in the lexer

Added by andrykonchin (Andrew Konchin) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

According to Regexp#source documentation:

Returns the original string of the pattern.
/ab+c/ix.source #=> "ab+c"

Note that escape sequences are retained as is.
/\x20\+/.source  #=> "\\x20\\+"

It works well but backslash (/) is processed in different way by different regexp literal forms.

Examples:

/\//.source # => "/"
%r/\//.source # => "/"
%r{\/}.source # => "\\/"

Expected result - in all the cases result is the same.

Moreover as documentation states - escape sequences are retained as is. So I would say that only %r{} works properly.

The issue was reported here https://github.com/oracle/truffleruby/issues/2569.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0