Skip to content

Commit d788786

Browse files
committed
Fix parsing of multiline URL values for rule sets
1 parent 5765e6c commit d788786

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/css_parser/rule_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def parse_declarations!(block) # :nodoc:
616616
decs = (continuation ? continuation + decs : decs)
617617
if decs =~ /\([^)]*\Z/ # if it has an unmatched parenthesis
618618
continuation = "#{decs};"
619-
elsif (matches = decs.match(/\s*(.[^:]*)\s*:\s*(.+?)(?:;?\s*\Z)/i))
619+
elsif (matches = decs.match(/\s*(.[^:]*)\s*:\s*(?m:(.+))(?:;?\s*\Z)/i))
620620
# skip end_of_declaration
621621
property = matches[1]
622622
value = matches[2]

test/test_css_parser_misc.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ def test_ignoring_malformed_declarations
113113
end
114114
end
115115

116+
def test_multiline_declarations
117+
css = <<-CSS
118+
@font-face {
119+
font-family: 'some_font';
120+
src: url(https://example.com/font.woff2) format('woff2'),
121+
url(https://example.com/font.woff) format('woff');
122+
font-style: normal;
123+
}
124+
CSS
125+
126+
@cp.add_block!(css)
127+
@cp.each_selector do |selector, declarations, _spec|
128+
assert_equal '@font-face', selector
129+
assert_equal "font-family: 'some_font'; " \
130+
"src: url(https://example.com/font.woff2) format('woff2')," \
131+
"url(https://example.com/font.woff) format('woff'); " \
132+
"font-style: normal;", declarations
133+
end
134+
end
135+
116136
def test_find_rule_sets
117137
css = <<-CSS
118138
h1, h2 { color: blue; }

0 commit comments

Comments
 (0)