Skip to content

Commit cf64ff9

Browse files
author
Andrey Fedoseev
committed
Fix URL converter to properly handle url(..) not followed directly by ;
1 parent 24d4f27 commit cf64ff9

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66
=====
77

88
- Add ``clean_css`` option to LESS compiler
9+
- Fix URL converter to properly handle ``url(..)`` not followed directly by ``;``
910

1011
1.8.1
1112
=====

static_precompiler/tests/test_url_converter.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ def test_convert_url():
1313
assert url_converter.convert_url("../images/dummy.jpg", "styles/") == "'/static/images/dummy.jpg'"
1414

1515

16-
def test_convert(monkeypatch):
16+
def test_convert():
1717

18-
monkeypatch.setattr(url_converter, "convert_url", lambda *args: "'spam.jpg'")
1918
assert (
20-
url_converter.convert("p {\n background-url: url(ham.jpg);\n}", "") ==
21-
"p {\n background-url: url('spam.jpg');\n}"
19+
url_converter.convert("p {\n background: url(../images/ham.jpg) no-repeat 0 0;\n}", "styles/") ==
20+
"p {\n background: url('/static/images/ham.jpg') no-repeat 0 0;\n}"
2221
)
2322
assert (
2423
url_converter.convert(
@@ -30,14 +29,10 @@ def test_convert(monkeypatch):
3029
'\'http://www.w3.org/2000/svg\' viewBox=\'0 0 8 8\'%3E%3Cpath fill=\'rgba(255, 255, 255, 0.97)'
3130
'\' d=\'M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z\'/%3E%3C/svg%3E");\n}'
3231
)
33-
assert (
34-
url_converter.convert("p {\n background-url: url('ham.jpg');\n}", "") ==
35-
"p {\n background-url: url('spam.jpg');\n}"
36-
)
3732
assert url_converter.convert(""".external_link:first-child:before {
3833
content: "Zobacz także:";
39-
background: url(картинка.png); }
40-
""", "") == """.external_link:first-child:before {
34+
background: url("../images/картинка.png"); }
35+
""", "styles/") == """.external_link:first-child:before {
4136
content: "Zobacz także:";
42-
background: url('spam.jpg'); }
37+
background: url("/static/images/картинка.png"); }
4338
"""

static_precompiler/url_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# noinspection PyUnresolvedReferences,PyCompatibility
1313
from urllib.parse import urljoin
1414

15-
URL_PATTERN = re.compile(r"url\(([^\)]+)\)(?=;)")
15+
URL_PATTERN = re.compile(r"url\((.+)\)")
1616

1717

1818
def convert_url(url, source_dir):

0 commit comments

Comments
 (0)