Skip to content

Commit 0d72fc0

Browse files
committed
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
1 parent 1ae0a5e commit 0d72fc0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

History.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
Ondruch
2727
* RDoc no longer quits when given an entry that is not a file or directory.
2828
Issue #101 by Charles Nutter
29+
* Fixed bug in syntax-highlighting that would corrupt regular expressions.
30+
Ruby Bug #6488 by Benny Lyne Amorsen.
2931

3032
=== 3.12 / 2011-12-15
3133

lib/rdoc/ruby_lex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ def identify_string(ltype, quoted = ltype, type = nil)
11631163
@ltype = ltype
11641164
@quoted = quoted
11651165

1166-
str = if ltype == quoted and %w[" '].include? ltype then
1166+
str = if ltype == quoted and %w[" ' /].include? ltype then
11671167
ltype.dup
11681168
elsif RUBY_VERSION > '1.9' then
11691169
"%#{type or PERCENT_LTYPE.key ltype}#{PERCENT_PAREN_REV[quoted]}"

test/test_rdoc_ruby_lex.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ def test_class_tokenize_heredoc_percent_N
9494
assert_equal expected, tokens
9595
end
9696

97+
def test_class_tokenize_percent_r
98+
tokens = RDoc::RubyLex.tokenize '%r[hi]', nil
99+
100+
expected = [
101+
@TK::TkREGEXP.new( 0, 1, 0, '%r[hi]'),
102+
@TK::TkNL .new( 6, 1, 6, "\n"),
103+
]
104+
105+
assert_equal expected, tokens
106+
end
107+
97108
def test_class_tokenize_percent_w
98109
tokens = RDoc::RubyLex.tokenize '%w[hi]', nil
99110

@@ -105,6 +116,17 @@ def test_class_tokenize_percent_w
105116
assert_equal expected, tokens
106117
end
107118

119+
def test_class_tokenize_regexp
120+
tokens = RDoc::RubyLex.tokenize "/hay/", nil
121+
122+
expected = [
123+
@TK::TkREGEXP.new( 0, 1, 0, "/hay/"),
124+
@TK::TkNL .new( 5, 1, 5, "\n"),
125+
]
126+
127+
assert_equal expected, tokens
128+
end
129+
108130
def test_class_tokenize_string
109131
tokens = RDoc::RubyLex.tokenize "'hi'", nil
110132

0 commit comments

Comments
 (0)