Permalink
Browse files

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
  • Loading branch information...
1 parent 0d72fc0 commit eaf2b80cd38e7e8c9386df95ae360ba8ace13465 @drbrain drbrain committed Jun 1, 2012
Showing with 19 additions and 6 deletions.
  1. +8 −6 lib/rdoc/ruby_lex.rb
  2. +11 −0 test/test_rdoc_ruby_lex.rb
View
@@ -1189,14 +1189,16 @@ def identify_string(ltype, quoted = ltype, type = nil)
else
ungetc
end
- elsif ch == '\\' and @ltype == "'" #'
- case ch = getc
- when "\\", "\n", "'"
+ elsif ch == '\\'
+ if %w[' /].include? @ltype then
+ case ch = getc
+ when "\\", "\n", "'"
+ else
+ ungetc
+ end
else
- ungetc
+ str << read_escape
end
- elsif ch == '\\' #'
- str << read_escape
end
if close then
View
@@ -127,6 +127,17 @@ def test_class_tokenize_regexp
assert_equal expected, tokens
end
+ def test_class_tokenize_regexp_backref
+ tokens = RDoc::RubyLex.tokenize "/[csh](..) [csh]\\1 in/", nil
+
+ expected = [
+ @TK::TkREGEXP.new( 0, 1, 0, "/[csh](..) [csh]\\1 in/"),
+ @TK::TkNL .new(22, 1, 22, "\n"),
+ ]
+
+ assert_equal expected, tokens
+ end
+
def test_class_tokenize_string
tokens = RDoc::RubyLex.tokenize "'hi'", nil

0 comments on commit eaf2b80

Please sign in to comment.