Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-pipeline
Commits
a385dce6
Commit
a385dce6
authored
Dec 25, 2013
by
Tomek Paczkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not rewrite data URIs
parent
daa77d5c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
4 deletions
+17
-4
pipeline/compressors/__init__.py
+2
-1
tests/assets/css/nested/nested.css
+3
-0
tests/assets/css/urls.css
+1
-2
tests/tests/test_compressor.py
+11
-1
No files found.
pipeline/compressors/__init__.py
View file @
a385dce6
...
...
@@ -16,6 +16,7 @@ from pipeline.exceptions import CompressorError
URL_DETECTOR
=
r'url\([\'"]?([^\s)]+\.[a-z]+[^\'"\s]*)[\'"]?\)'
URL_REPLACER
=
r'url\(__EMBED__(.+?)(\?\d+)?\)'
NON_REWRITABLE_URL
=
re
.
compile
(
r'^(http:|https:|data:|//)'
)
DEFAULT_TEMPLATE_FUNC
=
"template"
TEMPLATE_FUNC
=
r"""var template = function(str){var fn = new Function('obj', 'var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(\''+str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/<
%
=([\s\S]+?)
%
>/g,function(match,code){return "',"+code.replace(/\\'/g, "'")+",'";}).replace(/<
%
([\s\S]+?)
%
>/g,function(match,code){return "');"+code.replace(/\\'/g, "'").replace(/[\r\n\t]/g,' ')+"__p.push('";}).replace(/\r/g,'\\r').replace(/\n/g,'\\n').replace(/\t/g,'\\t')+"');}return __p.join('');");return fn;};"""
...
...
@@ -125,7 +126,7 @@ class Compressor(object):
for
path
in
paths
:
def
reconstruct
(
match
):
asset_path
=
match
.
group
(
1
)
if
asset_path
.
startswith
(
"http"
)
or
asset_path
.
startswith
(
"//"
):
if
NON_REWRITABLE_URL
.
match
(
asset_path
):
return
"url(
%
s)"
%
asset_path
asset_url
=
self
.
construct_asset_path
(
asset_path
,
path
,
output_filename
,
variant
)
...
...
tests/assets/css/nested/nested.css
0 → 100644
View file @
a385dce6
.data-url
{
background-image
:
url(data:image/svg+xml;charset=US-ASCII,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22iso-8859-1%22%3F%3E%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%20%20width%3D%2212px%22%20height%3D%2214px%22%20viewBox%3D%220%200%2012%2014%22%20style%3D%22enable-background%3Anew%200%200%2012%2014%3B%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpath%20d%3D%22M11%2C6V5c0-2.762-2.239-5-5-5S1%2C2.238%2C1%2C5v1H0v8h12V6H11z%20M6.5%2C9.847V12h-1V9.847C5.207%2C9.673%2C5%2C9.366%2C5%2C9%20c0-0.553%2C0.448-1%2C1-1s1%2C0.447%2C1%2C1C7%2C9.366%2C6.793%2C9.673%2C6.5%2C9.847z%20M9%2C6H3V5c0-1.657%2C1.343-3%2C3-3s3%2C1.343%2C3%2C3V6z%22%2F%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3Cg%3E%3C%2Fg%3E%3C%2Fsvg%3E)
;
}
tests/assets/css/urls.css
View file @
a385dce6
...
...
@@ -20,4 +20,4 @@
}
.no-protocol-url
{
background-image
:
url(//images/sprite-buttons.png)
;
}
\ No newline at end of file
}
tests/tests/test_compressor.py
View file @
a385dce6
...
...
@@ -140,7 +140,17 @@ class CompressorTest(TestCase):
}
.no-protocol-url {
background-image: url(//images/sprite-buttons.png);
}"""
,
output
)
}
"""
,
output
)
def
test_url_rewrite_data_uri
(
self
):
output
=
self
.
compressor
.
concatenate_and_rewrite
([
_
(
'pipeline/css/nested/nested.css'
),
],
'pipeline/screen.css'
)
self
.
assertEqual
(
""".data-url {
background-image: url(data:image/svg+xml;charset=US-ASCII,
%3
C
%3
Fxml
%20
version
%3
D
%221.0%22%20
encoding
%3
D
%22
iso-8859-1
%22%3
F
%3
E
%3
C!DOCTYPE
%20
svg
%20
PUBLIC
%20%22
-
%2
F
%2
FW3C
%2
F
%2
FDTD
%20
SVG
%201.1%2
F
%2
FEN
%22%20%22
http
%3
A
%2
F
%2
Fwww.w3.org
%2
FGraphics
%2
FSVG
%2
F1.1
%2
FDTD
%2
Fsvg11.dtd
%22%3
E
%3
Csvg
%20
version
%3
D
%221.1%22%20
id
%3
D
%22
Layer_1
%22%20
xmlns
%3
D
%22
http
%3
A
%2
F
%2
Fwww.w3.org
%2
F2000
%2
Fsvg
%22%20
xmlns
%3
Axlink
%3
D
%22
http
%3
A
%2
F
%2
Fwww.w3.org
%2
F1999
%2
Fxlink
%22%20
x
%3
D
%220
px
%22%20
y
%3
D
%220
px
%22%20%20
width
%3
D
%2212
px
%22%20
height
%3
D
%2214
px
%22%20
viewBox
%3
D
%220%200%2012%2014%22%20
style
%3
D
%22
enable-background
%3
Anew
%200%200%2012%2014%3
B
%22%20
xml
%3
Aspace
%3
D
%22
preserve
%22%3
E
%3
Cpath
%20
d
%3
D
%22
M11
%2
C6V5c0-2.762-2.239-5-5-5S1
%2
C2.238
%2
C1
%2
C5v1H0v8h12V6H11z
%20
M6.5
%2
C9.847V12h-1V9.847C5.207
%2
C9.673
%2
C5
%2
C9.366
%2
C5
%2
C9
%20
c0-0.553
%2
C0.448-1
%2
C1-1s1
%2
C0.447
%2
C1
%2
C1C7
%2
C9.366
%2
C6.793
%2
C9.673
%2
C6.5
%2
C9.847z
%20
M9
%2
C6H3V5c0-1.657
%2
C1.343-3
%2
C3-3s3
%2
C1.343
%2
C3
%2
C3V6z
%22%2
F
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
Cg
%3
E
%3
C
%2
Fg
%3
E
%3
C
%2
Fsvg
%3
E);
}
"""
,
output
)
def
test_compressor_subprocess_unicode
(
self
):
tests_path
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment