Skip to content

Commit 9a2edcc

Browse files
committed
refactor erb scanner open tag matching to fix a minor bug
1 parent b256ecf commit 9a2edcc

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/coderay/scanners/erb.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class ERB < Scanner
1313
KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
1414

1515
ERB_RUBY_BLOCK = /
16-
<%(?!%)[=-]?
17-
(?>
16+
(<%(?!%)[-=\#]?)
17+
((?>
1818
[^\-%]* # normal*
1919
(?> # special
2020
(?: %(?!>) | -(?!%>) )
2121
[^\-%]* # normal*
2222
)*
23-
)
24-
(?: -?%> )?
23+
))
24+
((?: -?%> )?)
2525
/x # :nodoc:
2626

2727
START_OF_ERB = /
@@ -48,21 +48,25 @@ def scan_tokens encoder, options
4848
@html_scanner.tokenize match, :tokens => encoder
4949

5050
elsif match = scan(/#{ERB_RUBY_BLOCK}/o)
51-
start_tag = match[/\A<%[-=#]?/]
52-
end_tag = match[/-?%?>?\z/]
51+
start_tag = self[1]
52+
code = self[2]
53+
end_tag = self[3]
54+
5355
encoder.begin_group :inline
5456
encoder.text_token start_tag, :inline_delimiter
55-
code = match[start_tag.size .. -1 - end_tag.size]
56-
if start_tag[/\A<%#/]
57+
58+
if start_tag == '<%#'
5759
encoder.text_token code, :comment
5860
else
5961
@ruby_scanner.tokenize code, :tokens => encoder
6062
end unless code.empty?
63+
6164
encoder.text_token end_tag, :inline_delimiter unless end_tag.empty?
6265
encoder.end_group :inline
6366

6467
else
6568
raise_inspect 'else-case reached!', encoder
69+
6670
end
6771

6872
end

0 commit comments

Comments
 (0)