Skip to content

Commit e2a75c6

Browse files
author
JoseLuis Torres
committed
adding the validation for single special character in attribute zmoazeni#70
1 parent 1e3b3b7 commit e2a75c6

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

lib/csscss/parser/css.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class Parser < Parslet::Parser
1919

2020
rule(:blank_attribute) { str(";") >> space? }
2121

22-
rule(:attribute_value) { (str('/*').absent? >> match["^;}"]) | raw_comment }
22+
rule(:attribute_value) { (str('"') >> any >> str('"')) | (str('/*').absent? >> match["^;}"]) | raw_comment }
2323

2424
rule(:attribute) {
2525
match["^:{}"].repeat(1).as(:property) >>
2626
str(":") >>
2727
(
2828
(stri("data:").absent? >> attribute_value) |
29-
(stri("data:").present? >> attribute_value.repeat(1) >> str(";") >> attribute_value.repeat(1))
29+
(stri("data:").present? >> attribute_value.repeat(1) >> str(";") >> attribute_value.repeat(1))
3030
).repeat(1).as(:value) >>
3131
str(";").maybe >>
3232
space?

test/csscss/parser/common_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ class CommonTest
139139
@parser.url.must_parse "url(data:image/svg+xml;base64,IMGDATAGOESHERE4/5/h/1+==)"
140140
@parser.url.must_parse "url('data:image/svg+xml;base64,IMGDATAGOESHERE4/5/h/1+==')"
141141
end
142+
143+
it "parses specials characters" do
144+
@parser.between('"', '"') { @parser.symbol("{") }.must_parse '"{"'
145+
@parser.between('"', '"') { @parser.symbol("}") }.must_parse '"}"'
146+
@parser.between('"', '"') { @parser.symbol("%") }.must_parse '"%"'
147+
end
142148
end
143149
end
144150
end

test/csscss/parser/css_test.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,39 @@ module Css
212212
dec("display", "block")])
213213
])
214214
end
215+
216+
it "parses attributes with special characters" do
217+
css = %$
218+
219+
#menu a::before {
220+
content: "{";
221+
left: -6px;
222+
}
223+
224+
#menu a::after {
225+
content: "}";
226+
right: -6px;
227+
}
228+
229+
#menu a::weird {
230+
content: "@";
231+
up: -2px;
232+
}
233+
234+
$
235+
236+
trans(css).must_equal([
237+
rs(sel("#menu a::before"), [dec("content", '"{"'),
238+
dec("left", "-6px")
239+
]),
240+
rs(sel("#menu a::after"), [dec("content", '"}"'),
241+
dec("right", "-6px")
242+
]),
243+
rs(sel("#menu a::weird"), [dec("content", '"@"'),
244+
dec("up", "-2px")
245+
])
246+
])
247+
end
215248
end
216249
end
217250
end

0 commit comments

Comments
 (0)