Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 0d72fc0d025c882f0c03e98c15ceefb472e19a7e 1 parent 1ae0a5e
@drbrain drbrain authored
View
2  History.rdoc
@@ -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
2  lib/rdoc/ruby_lex.rb
@@ -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
22 test/test_rdoc_ruby_lex.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.