Permalink
Browse files

Fixed syntax highlighting of regular expressions

In HTML output, syntax highlighting of regular expressions could become
corrupted.  This patch whitelists "/" as a character with a matching
terminal like '"' and "'" for strings.

See also Ruby Bug #6488 and #6523
  • Loading branch information...
1 parent 1ae0a5e commit 0d72fc0d025c882f0c03e98c15ceefb472e19a7e @drbrain drbrain committed Jun 1, 2012
Showing with 25 additions and 1 deletion.
  1. +2 −0 History.rdoc
  2. +1 −1 lib/rdoc/ruby_lex.rb
  3. +22 −0 test/test_rdoc_ruby_lex.rb
View
@@ -26,6 +26,8 @@
Ondruch
* RDoc no longer quits when given an entry that is not a file or directory.
Issue #101 by Charles Nutter
+ * Fixed bug in syntax-highlighting that would corrupt regular expressions.
+ Ruby Bug #6488 by Benny Lyne Amorsen.
=== 3.12 / 2011-12-15
View
@@ -1163,7 +1163,7 @@ def identify_string(ltype, quoted = ltype, type = nil)
@ltype = ltype
@quoted = quoted
- str = if ltype == quoted and %w[" '].include? ltype then
+ str = if ltype == quoted and %w[" ' /].include? ltype then
ltype.dup
elsif RUBY_VERSION > '1.9' then
"%#{type or PERCENT_LTYPE.key ltype}#{PERCENT_PAREN_REV[quoted]}"
View
@@ -94,6 +94,17 @@ def test_class_tokenize_heredoc_percent_N
assert_equal expected, tokens
end
+ def test_class_tokenize_percent_r
+ tokens = RDoc::RubyLex.tokenize '%r[hi]', nil
+
+ expected = [
+ @TK::TkREGEXP.new( 0, 1, 0, '%r[hi]'),
+ @TK::TkNL .new( 6, 1, 6, "\n"),
+ ]
+
+ assert_equal expected, tokens
+ end
+
def test_class_tokenize_percent_w
tokens = RDoc::RubyLex.tokenize '%w[hi]', nil
@@ -105,6 +116,17 @@ def test_class_tokenize_percent_w
assert_equal expected, tokens
end
+ def test_class_tokenize_regexp
+ tokens = RDoc::RubyLex.tokenize "/hay/", nil
+
+ expected = [
+ @TK::TkREGEXP.new( 0, 1, 0, "/hay/"),
+ @TK::TkNL .new( 5, 1, 5, "\n"),
+ ]
+
+ assert_equal expected, tokens
+ end
+
def test_class_tokenize_string
tokens = RDoc::RubyLex.tokenize "'hi'", nil

0 comments on commit 0d72fc0

Please sign in to comment.