Skip to content

Commit 15f1916

Browse files
committed
Use string serialization to serialize url()
That’s what’s proposed by CSSOM: https://www.w3.org/TR/2021/WD-cssom-1-20210826/#serialize-a-url
1 parent c50bef4 commit 15f1916

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

tinycss2/serializer.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,6 @@ def serialize_string_value(value):
8484
return _re_string_value.sub(_serialize_string_value_match, value)
8585

8686

87-
def serialize_url(value):
88-
return ''.join(
89-
r"\'" if c == "'" else
90-
r'\"' if c == '"' else
91-
r'\\' if c == '\\' else
92-
r'\ ' if c == ' ' else
93-
r'\9 ' if c == '\t' else
94-
r'\A ' if c == '\n' else
95-
r'\D ' if c == '\r' else
96-
r'\C ' if c == '\f' else
97-
r'\(' if c == '(' else
98-
r'\)' if c == ')' else
99-
c
100-
for c in value
101-
)
102-
103-
10487
# https://drafts.csswg.org/css-syntax/#serialization-tables
10588
def _serialize_to(nodes, write):
10689
"""Serialize an iterable of nodes to CSS syntax.

tinycss2/tokenizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
HashToken, IdentToken, LiteralToken, NumberToken, ParenthesesBlock, ParseError,
99
PercentageToken, SquareBracketsBlock, StringToken, UnicodeRangeToken, URLToken,
1010
WhitespaceToken)
11-
from .serializer import serialize_string_value, serialize_url
11+
from .serializer import serialize_string_value
1212

1313
_NUMBER_RE = re.compile(r'[-+]?([0-9]*\.)?[0-9]+([eE][+-]?[0-9]+)?')
1414
_HEX_ESCAPE_RE = re.compile(r'([0-9A-Fa-f]{1,6})[ \n\t]?')
@@ -77,7 +77,7 @@ def parse_component_value_list(css, skip_comments=False):
7777
if url_pos >= length or css[url_pos] not in ('"', "'"):
7878
value, pos, error = _consume_url(css, pos)
7979
if value is not None:
80-
repr = 'url({})'.format(serialize_url(value))
80+
repr = 'url("{}")'.format(serialize_string_value(value))
8181
if error is not None:
8282
error_key = error[0]
8383
if error_key == 'eof-in-string':

0 commit comments

Comments
 (0)