Skip to content

Commit 5918b95

Browse files
committed
Make the regex less permissive
1 parent 3f4cdea commit 5918b95

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class AssetRewrite extends Filter {
9393
* ["\'(=] - Match one of "'(= exactly one time
9494
* \\s* - Any amount of white space
9595
* ( - Starts the first capture group
96-
* [^"\'()=]* - Do not match any of ^"'()= 0 or more times
97-
* [^"\n\'()\\>=]* - Do not match any of ^"\n'()\>= 0 or more times - Explicitly add \ here because of handlebars compilation
96+
* (\\.?/)? - Optionally match ./ or /
97+
* [^"\n\'()\\>=]* - Match any character not in ^"\n'()\>= 0 or more times - Explicitly add \ here because of handlebars compilation
9898
* ) - End first capture group
9999
* (\\?[^"\')> ]*)? - Allow for query parameters to be present after the URL of an asset
100100
* \\s* - Any amount of white space
@@ -104,7 +104,7 @@ class AssetRewrite extends Filter {
104104
*/
105105

106106
var re = new RegExp(
107-
'["\'(=]\\s*([^"\'()=]*' +
107+
'["\'(=]\\s*((\\.?/)?' +
108108
escapeRegExp(assetPath) +
109109
'[^"\n\'()\\>=]*)(\\?[^"\')> ]*)?\\s*\\\\*\\s*["\')>s]',
110110
'g'

tests/filter-tests.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('broccoli-asset-rev', function () {
3131
src: url('fonts/Fiz/Light/Fiz-Light.eot');
3232
src: url('fonts/Fiz/Light/Fiz-Light.eot?#iefix') format('embedded-opentype'), url('fonts/Fiz/Light/Fiz-Light.woff') format('woff'), url('fonts/Fiz/Light/Fiz-Light.ttf') format('truetype'), url('fonts/Fiz/Light/Fiz-Light.svg#Fiz') format('svg');
3333
}
34-
34+
3535
@font-face {
3636
font-family: Fiz;
3737
font-weight: 200;
@@ -62,7 +62,7 @@ describe('broccoli-asset-rev', function () {
6262
src: url('fonts/Fiz/Light/fingerprinted-Fiz-Light.eot');
6363
src: url('fonts/Fiz/Light/fingerprinted-Fiz-Light.eot?#iefix') format('embedded-opentype'), url('fonts/Fiz/Light/fingerprinted-Fiz-Light.woff') format('woff'), url('fonts/Fiz/Light/fingerprinted-Fiz-Light.ttf') format('truetype'), url('fonts/Fiz/Light/fingerprinted-Fiz-Light.svg#Fiz') format('svg');
6464
}
65-
65+
6666
@font-face {
6767
font-family: Fiz;
6868
font-weight: 200;
@@ -521,4 +521,44 @@ describe('broccoli-asset-rev', function () {
521521

522522
expect(run2ProcessedCount).to.equal(0);
523523
});
524+
525+
it('ignores remote URLs', async function () {
526+
var sourcePath = 'tests/fixtures/remote-url';
527+
var node = new AssetRewrite(sourcePath + '/input', {
528+
replaceExtensions: ['js'],
529+
assetMap: {
530+
'the.map': 'the-other-map',
531+
'app.js': 'http://cdn.absolute.com/app.js',
532+
},
533+
prepend: '/',
534+
});
535+
536+
let output = createBuilder(node);
537+
538+
await output.build();
539+
540+
expect(output.read()).to.deep.equal({
541+
'snippet.js': '<script src="http://example.com/app/app.js"></script>\n',
542+
});
543+
});
544+
545+
it('ignores partial matches', async function () {
546+
var sourcePath = 'tests/fixtures/partial-match';
547+
var node = new AssetRewrite(sourcePath + '/input', {
548+
replaceExtensions: ['js'],
549+
assetMap: {
550+
'the.map': 'the-other-map',
551+
'app.js': 'http://cdn.absolute.com/app.js',
552+
},
553+
prepend: '/',
554+
});
555+
556+
let output = createBuilder(node);
557+
558+
await output.build();
559+
560+
expect(output.read()).to.deep.equal({
561+
'snippet.js': '<script src="other-app/app.js"></script>\n',
562+
});
563+
});
524564
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="other-app/app.js"></script>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="http://example.com/app/app.js"></script>

0 commit comments

Comments
 (0)