From dbbda0835a48cd43686c7ea4a0ac9bd1fe14318f Mon Sep 17 00:00:00 2001 From: Rein Henrichs Date: Thu, 14 Nov 2013 14:48:14 -0800 Subject: [PATCH 1/2] Do not strip regexp literal options [fixes #259] Ensure that the lexer includes any option, like /foo/i, when lexing regexp literals. --- lib/rdoc/ruby_lex.rb | 2 +- test/test_rdoc_ruby_lex.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rdoc/ruby_lex.rb b/lib/rdoc/ruby_lex.rb index 06a82ef978..8f0412b087 100644 --- a/lib/rdoc/ruby_lex.rb +++ b/lib/rdoc/ruby_lex.rb @@ -1232,7 +1232,7 @@ def identify_string(ltype, quoted = ltype, type = nil) if @ltype == "/" if peek(0) =~ /i|m|x|o|e|s|u|n/ - getc + str << getc end end diff --git a/test/test_rdoc_ruby_lex.rb b/test/test_rdoc_ruby_lex.rb index 28eee276d8..d35457b871 100644 --- a/test/test_rdoc_ruby_lex.rb +++ b/test/test_rdoc_ruby_lex.rb @@ -247,7 +247,7 @@ def test_class_tokenize_regexp_options expected = [ @TK::TkREGEXP.new( 0, 1, 0, "/hAY/i"), - @TK::TkNL .new( 5, 1, 5, "\n"), + @TK::TkNL .new( 6, 1, 6, "\n"), ] assert_equal expected, tokens From ab32c3bed22598d0b5b9f446fcc88c52576f167e Mon Sep 17 00:00:00 2001 From: Rein Henrichs Date: Thu, 14 Nov 2013 14:53:57 -0800 Subject: [PATCH 2/2] Correctly handle multiple options "if is a degenerate while" :D --- lib/rdoc/ruby_lex.rb | 2 +- test/test_rdoc_ruby_lex.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/ruby_lex.rb b/lib/rdoc/ruby_lex.rb index 8f0412b087..d470d2b5f8 100644 --- a/lib/rdoc/ruby_lex.rb +++ b/lib/rdoc/ruby_lex.rb @@ -1231,7 +1231,7 @@ def identify_string(ltype, quoted = ltype, type = nil) end if @ltype == "/" - if peek(0) =~ /i|m|x|o|e|s|u|n/ + while peek(0) =~ /i|m|x|o|e|s|u|n/ str << getc end end diff --git a/test/test_rdoc_ruby_lex.rb b/test/test_rdoc_ruby_lex.rb index d35457b871..22cf0f6295 100644 --- a/test/test_rdoc_ruby_lex.rb +++ b/test/test_rdoc_ruby_lex.rb @@ -251,6 +251,15 @@ def test_class_tokenize_regexp_options ] assert_equal expected, tokens + + tokens = RDoc::RubyLex.tokenize "/hAY/ix", nil + + expected = [ + @TK::TkREGEXP.new( 0, 1, 0, "/hAY/ix"), + @TK::TkNL .new( 7, 1, 7, "\n"), + ] + + assert_equal expected, tokens end def test_class_tokenize_regexp_backref