Skip to content

Commit 6580451

Browse files
committed
Fixed Regexp backreference corruption
Regular expression parsing was switched to use single-quote escaping rules. Using double quote rules, extra backslashes and white spaces was added. See also Ruby Bug #6488 and #6523
1 parent c24963c commit 6580451

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,16 @@ def identify_string(ltype, quoted = ltype, type = nil)
11891189
else
11901190
ungetc
11911191
end
1192-
elsif ch == '\\' and @ltype == "'" #'
1193-
case ch = getc
1194-
when "\\", "\n", "'"
1192+
elsif ch == '\\'
1193+
if %w[' /].include? @ltype then
1194+
case ch = getc
1195+
when "\\", "\n", "'"
1196+
else
1197+
ungetc
1198+
end
11951199
else
1196-
ungetc
1200+
str << read_escape
11971201
end
1198-
elsif ch == '\\' #'
1199-
str << read_escape
12001202
end
12011203

12021204
if close then

test/test_rdoc_ruby_lex.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ def test_class_tokenize_regexp
127127
assert_equal expected, tokens
128128
end
129129

130+
def test_class_tokenize_regexp_backref
131+
tokens = RDoc::RubyLex.tokenize "/[csh](..) [csh]\\1 in/", nil
132+
133+
expected = [
134+
@TK::TkREGEXP.new( 0, 1, 0, "/[csh](..) [csh]\\1 in/"),
135+
@TK::TkNL .new(22, 1, 22, "\n"),
136+
]
137+
138+
assert_equal expected, tokens
139+
end
140+
130141
def test_class_tokenize_string
131142
tokens = RDoc::RubyLex.tokenize "'hi'", nil
132143

0 commit comments

Comments
 (0)