Skip to content

Commit

Permalink
Use string serialization to serialize url()
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jan 15, 2025
1 parent c50bef4 commit 15f1916
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
17 changes: 0 additions & 17 deletions tinycss2/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,6 @@ def serialize_string_value(value):
return _re_string_value.sub(_serialize_string_value_match, value)


def serialize_url(value):
return ''.join(
r"\'" if c == "'" else
r'\"' if c == '"' else
r'\\' if c == '\\' else
r'\ ' if c == ' ' else
r'\9 ' if c == '\t' else
r'\A ' if c == '\n' else
r'\D ' if c == '\r' else
r'\C ' if c == '\f' else
r'\(' if c == '(' else
r'\)' if c == ')' else
c
for c in value
)


# https://drafts.csswg.org/css-syntax/#serialization-tables
def _serialize_to(nodes, write):
"""Serialize an iterable of nodes to CSS syntax.
Expand Down
4 changes: 2 additions & 2 deletions tinycss2/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
HashToken, IdentToken, LiteralToken, NumberToken, ParenthesesBlock, ParseError,
PercentageToken, SquareBracketsBlock, StringToken, UnicodeRangeToken, URLToken,
WhitespaceToken)
from .serializer import serialize_string_value, serialize_url
from .serializer import serialize_string_value

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

0 comments on commit 15f1916

Please sign in to comment.