Skip to content

Commit

Permalink
Merge pull request #64 from gojefferson/patch-1
Browse files Browse the repository at this point in the history
Update regex for finding instances of assetPath
  • Loading branch information
rickharrison authored Aug 13, 2018
2 parents 212cd52 + dc755cb commit b841f23
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,18 @@ AssetRewrite.prototype.rewriteAssetPath = function (string, assetPath, replaceme
* \\s* - Any amount of white space
* ( - Starts the first capture group
* [^"\'()=]* - Do not match any of ^"'()= 0 or more times
* [^"\'()\\>=]* - Do not match any of ^"'()\>= 0 or more times - Explicitly add \ here because of handlebars compilation
* [^"\n\'()\\>=]* - Do not match any of ^"\n'()\>= 0 or more times - Explicitly add \ here because of handlebars compilation
* ) - End first capture group
* (\\?[^"\')> ]*)? - Allow for query parameters to be present after the URL of an asset
* \\s* - Any amount of white space
* \\\\* - Allow any amount of \ - For handlebars compilation (includes \\\)
* \\s* - Any amount of white space
* ["\')> ] - Match one of "'( > exactly one time
* ["\')>\s] - Match one of "'(\n> exactly one time
*/

var re = new RegExp('["\'(=]\\s*([^"\'()=]*' + escapeRegExp(assetPath) + '[^"\'()\\>=]*)(\\?[^"\')> ]*)?\\s*\\\\*\\s*["\')> ]', 'g');
var re = new RegExp('["\'(=]\\s*([^"\'()=]*' + escapeRegExp(assetPath) + '[^"\n\'()\\>=]*)(\\?[^"\')> ]*)?\\s*\\\\*\\s*["\')>\s]', 'g');
var match = null;

/*
* This is to ignore matches that should not be changed
* Any URL encoded match that would be ignored above will be ignored by this: "'()=\
Expand Down
18 changes: 17 additions & 1 deletion tests/filter-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ describe('broccoli-asset-rev', function() {
});
});


it('handles JavaScript files in a reasonable amount of time', function () {
this.timeout(500);
var sourcePath = 'tests/fixtures/js-perf';
Expand All @@ -233,4 +232,21 @@ describe('broccoli-asset-rev', function() {
confirmOutput(graph.directory, sourcePath + '/output');
})
});

it('ignores JavaScript comments with URLs', function () {
var sourcePath = 'tests/fixtures/js-comment';
var node = new AssetRewrite(sourcePath + '/input', {
replaceExtensions: ['js'],
assetMap: {
'the.map': 'the-other-map',
'app.js': 'http://cdn.absolute.com/app.js'
},
prepend: '/'
});

builder = new broccoli.Builder(node);
return builder.build().then(function (graph) {
confirmOutput(graph.directory, sourcePath + '/output');
});
});
});
12 changes: 12 additions & 0 deletions tests/fixtures/js-comment/input/snippet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
here's some code.
it does things.
for example:
```app/app.js
do not rewrite this snippet
```
*/
(function x() { return true; })
12 changes: 12 additions & 0 deletions tests/fixtures/js-comment/output/snippet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
here's some code.
it does things.
for example:
```app/app.js
do not rewrite this snippet
```
*/
(function x() { return true; })

0 comments on commit b841f23

Please sign in to comment.