File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
lib/active_support/core_ext/erb Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change
1
+ * Fix a bug in ` ERB::Util.tokenize ` that causes incorrect tokenization when ERB tags are preceeded by multibyte characters.
2
+
3
+ * Martin Emde*
4
+
1
5
* Add ` ActiveSupport::Testing::NotificationAssertions ` module to help with testing ` ActiveSupport::Notifications ` .
2
6
3
7
* Nicholas La Roux* , * Yishu See* , * Sean Doyle*
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ def self.tokenize(source) # :nodoc:
174
174
175
175
case source . matched
176
176
when start_re
177
- tokens << [ :TEXT , source . string [ pos , len ] ] if len > 0
177
+ tokens << [ :TEXT , source . string . byteslice ( pos , len ) ] if len > 0
178
178
tokens << [ :OPEN , source . matched ]
179
179
if source . scan ( /(.*?)(?=#{ finish_re } |\z )/m )
180
180
tokens << [ :CODE , source . matched ] unless source . matched . empty?
@@ -183,7 +183,7 @@ def self.tokenize(source) # :nodoc:
183
183
raise NotImplementedError
184
184
end
185
185
when finish_re
186
- tokens << [ :CODE , source . string [ pos , len ] ] if len > 0
186
+ tokens << [ :CODE , source . string . byteslice ( pos , len ) ] if len > 0
187
187
tokens << [ :CLOSE , source . matched ]
188
188
else
189
189
raise NotImplementedError , source . matched
Original file line number Diff line number Diff line change @@ -135,6 +135,24 @@ def test_text_end
135
135
] , actual_tokens
136
136
end
137
137
138
+ def test_multibyte_characters_start
139
+ source = "こんにちは<%= name %>"
140
+ actual_tokens = tokenize source
141
+ assert_equal [ [ :TEXT , "こんにちは" ] ,
142
+ [ :OPEN , "<%=" ] ,
143
+ [ :CODE , " name " ] ,
144
+ [ :CLOSE , "%>" ] ,
145
+ ] , actual_tokens
146
+ end
147
+
148
+ def test_multibyte_characters_end
149
+ source = " 'こんにちは' %>"
150
+ actual_tokens = tokenize source
151
+ assert_equal [ [ :CODE , " 'こんにちは' " ] ,
152
+ [ :CLOSE , "%>" ] ,
153
+ ] , actual_tokens
154
+ end
155
+
138
156
def tokenize ( source )
139
157
ERB ::Util . tokenize source
140
158
end
You can’t perform that action at this time.
0 commit comments