Skip to content

Commit 4c011f2

Browse files
authored
Merge pull request #77 from jdav-dev/escaped_commas
Ignore escaped commas when splitting selectors
2 parents fde0b12 + d7cc66d commit 4c011f2

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* `Premailex.HTMLInlineStyles.process/3` now warns when styles can't be loaded from URL's
66
* `Premailex.HTMLInlineStyles.process/1` now parses `<thead>` and `<tfoot>` elements
7+
* `Premailex.CSSParser.parse/1` now handles escaped commas
78
* Require Elixir 1.11
89

910
## v0.3.16 (2022-07-01)

lib/premailex/css_parser.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ defmodule Premailex.CSSParser do
6262

6363
defp parse_selectors_rules([_, selector, rules]) do
6464
selector
65-
|> String.split(",")
65+
# Ignore escaped commas
66+
|> String.split(~r/(?<!\\),/)
6667
|> Enum.map(&parse_selector_rules(&1, rules))
6768
end
6869

test/premailex/css_parser_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defmodule Premailex.CSSParserTest do
1818
src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
1919
url("/fonts/OpenSans-Regular-webfont.woff") format("woff");
2020
}
21+
.with\\,escaped\\,commas {}
2122
"""
2223

2324
@parsed [
@@ -54,6 +55,11 @@ defmodule Premailex.CSSParserTest do
5455
],
5556
selector: "div p > a:hover",
5657
specificity: 4
58+
},
59+
%{
60+
rules: [],
61+
selector: ".with\\,escaped\\,commas",
62+
specificity: 1
5763
}
5864
]
5965

0 commit comments

Comments
 (0)