From: "mame (Yusuke Endoh)" Date: 2022-06-21T02:10:21+00:00 Subject: [ruby-core:109027] [Ruby master Feature#18838] Avoid swallowing regexp escapes in the lexer Issue #18838 has been updated by mame (Yusuke Endoh). Agreed with Jeremy. There is the same "inconsistency" in a string literal, but this is clearly by design. ``` puts 'foo\'bar' #=> foo'bar puts %q'foo\'bar' #=> foo'bar puts %q{foo\'bar} #=> foo\\'bar ``` ---------------------------------------- Feature #18838: Avoid swallowing regexp escapes in the lexer https://bugs.ruby-lang.org/issues/18838#change-98142 * Author: andrykonchin (Andrew Konchin) * Status: Closed * Priority: Normal ---------------------------------------- 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: ```ruby /\//.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. -- https://bugs.ruby-lang.org/ Unsubscribe: