@@ -33,7 +33,8 @@ class HTML < Scanner
33
33
)
34
34
35
35
IN_ATTRIBUTE = WordList ::CaseIgnoring . new ( nil ) .
36
- add ( EVENT_ATTRIBUTES , :script )
36
+ add ( EVENT_ATTRIBUTES , :script ) .
37
+ add ( [ 'style' ] , :style )
37
38
38
39
ATTR_NAME = /[\w .:-]+/ # :nodoc:
39
40
TAG_END = /\/ ?>/ # :nodoc:
@@ -79,10 +80,10 @@ def scan_java_script encoder, code
79
80
end
80
81
end
81
82
82
- def scan_css encoder , code
83
+ def scan_css encoder , code , state = [ :initial ]
83
84
if code && !code . empty?
84
85
@css_scanner ||= Scanners ::CSS . new '' , :keep_tokens => true
85
- @css_scanner . tokenize code , :tokens => encoder
86
+ @css_scanner . tokenize code , :tokens => encoder , :state => state
86
87
end
87
88
end
88
89
@@ -166,17 +167,21 @@ def scan_tokens encoder, options
166
167
encoder . text_token match , :attribute_value
167
168
state = :attribute
168
169
elsif match = scan ( /["']/ )
169
- if in_attribute == :script
170
- encoder . begin_group :inline
171
- encoder . text_token match , :inline_delimiter
170
+ if in_attribute == :script || in_attribute == :style
171
+ encoder . begin_group :string
172
+ encoder . text_token match , :delimiter
172
173
if scan ( /javascript:[ \t ]*/ )
173
174
encoder . text_token matched , :comment
174
175
end
175
176
code = scan_until ( match == '"' ? /(?="|\z )/ : /(?='|\z )/ )
176
- scan_java_script encoder , code
177
+ if in_attribute == :script
178
+ scan_java_script encoder , code
179
+ else
180
+ scan_css encoder , code , [ :block ]
181
+ end
177
182
match = scan ( /["']/ )
178
- encoder . text_token match , :inline_delimiter if match
179
- encoder . end_group :inline
183
+ encoder . text_token match , :delimiter if match
184
+ encoder . end_group :string
180
185
state = :attribute
181
186
in_attribute = nil
182
187
else
0 commit comments