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
8eab4284
Commit
8eab4284
authored
Aug 01, 2015
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #470 from lydell/safe-js-concat
Safely concatenate JavaScript
parents
7079de7a
2af0561d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
6 deletions
+14
-6
pipeline/compressors/__init__.py
+5
-1
tests/assets/js/first.js
+4
-2
tests/assets/js/second.js
+4
-2
tests/tests/test_compressor.py
+1
-1
No files found.
pipeline/compressors/__init__.py
View file @
8eab4284
...
...
@@ -142,7 +142,11 @@ class Compressor(object):
def
concatenate
(
self
,
paths
):
"""Concatenate together a list of files"""
return
"
\n
"
.
join
([
self
.
read_text
(
path
)
for
path
in
paths
])
# Note how a semicolon is added between the two files to make sure that
# their behavior is not changed. '(expression1)\n(expression2)' calls
# `expression1` with `expression2` as an argument! Superfluos semicolons
# are valid in JavaScript and will be removed by the minifier.
return
"
\n
;"
.
join
([
self
.
read_text
(
path
)
for
path
in
paths
])
def
construct_asset_path
(
self
,
asset_path
,
css_path
,
output_filename
,
variant
=
None
):
"""Return a rewritten asset URL for a stylesheet"""
...
...
tests/assets/js/first.js
View file @
8eab4284
function
concat
()
{
(
function
()
{
window
.
concat
=
function
()
{
console
.
log
(
arguments
);
}
}
}())
// No semicolon
tests/assets/js/second.js
View file @
8eab4284
function
cat
()
{
(
function
()
{
window
.
cat
=
function
()
{
console
.
log
(
"hello world"
);
}
}
}());
tests/tests/test_compressor.py
View file @
8eab4284
...
...
@@ -46,7 +46,7 @@ class CompressorTest(TestCase):
_
(
'pipeline/js/first.js'
),
_
(
'pipeline/js/second.js'
)
])
self
.
assertEqual
(
"""
function concat() {
\n
console.log(arguments);
\n
}
\n\n
function cat() {
\n
console.log("hello world");
\n
}
\n
"""
,
js
)
self
.
assertEqual
(
"""
(function() {
\n
window.concat = function() {
\n
console.log(arguments);
\n
}
\n
}()) // No semicolon
\n\n
;(function() {
\n
window.cat = function() {
\n
console.log("hello world");
\n
}
\n
}());
\n
"""
,
js
)
@patch.object
(
base64
,
'b64encode'
)
def
test_encoded_content
(
self
,
mock
):
...
...
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