Skip to content

Commit

Permalink
Handle weirder relative paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
joanniclaborde committed Dec 9, 2013
1 parent b76ecb6 commit 7d91db8
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tasks/filerev_replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function(grunt) {

function asset_path_regexp( asset_path ) {
return new RegExp( STARTING_DELIMITER + // p1
ASSET_PATH_START + escape_for_regexp( asset_path ) + ASSET_PATH_END + // p2
ASSET_PATH_START + escape_for_regexp( path.basename( asset_path ) ) + ASSET_PATH_END + // p2
ENDING_DELIMITER, // p3
'ig' );
}
Expand Down
1 change: 1 addition & 0 deletions test/expected/assets/compiled/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var path = '/images/ajax-loader.4e26f87c.gif#a';
var path = 'ajax-loader.gif';
var path = '/images/ajax-loader';
var path = '/images/ajax-loader.gif.bak';
var path = '/images/not-ajax-loader.gif';
var path = 'images/ajax-loader.gif';
var path = '/more/images/ajax-loader.gif';
var path = '/cool_images/ajax-loader.gif';
Expand Down
1 change: 1 addition & 0 deletions test/expected/assets/compiled/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ body { background: url('/images/ajax-loader.4e26f87c.gif#a'); }
body { background: url('ajax-loader.gif'); }
body { background: url('/images/ajax-loader'); }
body { background: url('/images/ajax-loader.gif.bak'); }
body { background: url('/images/not-ajax-loader.gif'); }
body { background: url('images/ajax-loader.gif'); }
body { background: url('/more/images/ajax-loader.gif'); }
body { background: url('/cool_images/ajax-loader.gif'); }
Expand Down
26 changes: 26 additions & 0 deletions test/expected/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Absolute path -->
<img src="/images/ajax-loader.4e26f87c.gif" />

<!-- Relative path -->
<img src="/images/ajax-loader.4e26f87c.gif" />
<img src="/images/ajax-loader.4e26f87c.gif" />
<img src="/images/ajax-loader.4e26f87c.gif" />

<!-- Delimiters -->
<img src="/images/ajax-loader.4e26f87c.gif" /><img src="/images/ajax-loader.4e26f87c.gif" />

<!-- Case insensitive -->
<img src="/images/ajax-loader.4e26f87c.gif" />

<!-- With query string and anchor -->
<img src="/images/ajax-loader.4e26f87c.gif?a=b" />
<img src="/images/ajax-loader.4e26f87c.gif#a" />

<!-- Invalid -->
<img src="ajax-loader.gif" />
<img src="/images/ajax-loader" />
<img src="/images/ajax-loader.gif.bak" />
<img src="/images/not-ajax-loader.gif" />
<img src="/more/images/ajax-loader.gif" />
<img src="/cool_images/ajax-loader.gif" />
<img src="http://othersite.com/images/ajax-loader.gif" />
1 change: 1 addition & 0 deletions test/expected/views/media/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<img src="ajax-loader.gif" />
<img src="/images/ajax-loader" />
<img src="/images/ajax-loader.gif.bak" />
<img src="/images/not-ajax-loader.gif" />
<img src="images/ajax-loader.gif" />
<img src="/more/images/ajax-loader.gif" />
<img src="/cool_images/ajax-loader.gif" />
Expand Down
9 changes: 9 additions & 0 deletions test/filerev_replace_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ exports.filerev_replace = {
html: function(test) {
test.expect(1);

var actual = grunt.file.read('tmp/views/index.html');
var expected = grunt.file.read('test/expected/views/index.html');
test.equal(actual, expected);

test.done();
},
html_subfolder: function(test) {
test.expect(1);

var actual = grunt.file.read('tmp/views/media/index.html');
var expected = grunt.file.read('test/expected/views/media/index.html');
test.equal(actual, expected);
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/assets/compiled/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var path = '/images/ajax-loader.gif';
// Relative path
var path = '/oops/../images/ajax-loader.gif';
var path = '../images/ajax-loader.gif';
var path = '../oops/../images/ajax-loader.gif';
var path = '../oops/../images/oops/../ajax-loader.gif';

// Delimiters
var path = "/images/ajax-loader.gif";
Expand All @@ -23,6 +23,7 @@ var path = '/images/ajax-loader.gif#a';
var path = 'ajax-loader.gif';
var path = '/images/ajax-loader';
var path = '/images/ajax-loader.gif.bak';
var path = '/images/not-ajax-loader.gif';
var path = 'images/ajax-loader.gif';
var path = '/more/images/ajax-loader.gif';
var path = '/cool_images/ajax-loader.gif';
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/assets/compiled/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ body { background: url('/images/ajax-loader.gif'); }
/* Relative path */
body { background: url('/oops/../images/ajax-loader.gif'); }
body { background: url('../images/ajax-loader.gif'); }
body { background: url('../oops/../images/ajax-loader.gif'); }
body { background: url('../oops/../images/oops/../ajax-loader.gif'); }

/* Delimiters */
body { background: url("/images/ajax-loader.gif"); }
Expand All @@ -23,6 +23,7 @@ body { background: url('/images/ajax-loader.gif#a'); }
body { background: url('ajax-loader.gif'); }
body { background: url('/images/ajax-loader'); }
body { background: url('/images/ajax-loader.gif.bak'); }
body { background: url('/images/not-ajax-loader.gif'); }
body { background: url('images/ajax-loader.gif'); }
body { background: url('/more/images/ajax-loader.gif'); }
body { background: url('/cool_images/ajax-loader.gif'); }
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Absolute path -->
<img src="/images/ajax-loader.gif" />

<!-- Relative path -->
<img src="/oops/../images/ajax-loader.gif" />
<img src="images/ajax-loader.gif" />
<img src="oops/../images/oops/../ajax-loader.gif" />

<!-- Delimiters -->
<img src="/images/ajax-loader.gif" /><img src="/images/ajax-loader.gif" />

<!-- Case insensitive -->
<img src="/IMAGES/ajax-loader.gif" />

<!-- With query string and anchor -->
<img src="/images/ajax-loader.gif?a=b" />
<img src="/images/ajax-loader.gif#a" />

<!-- Invalid -->
<img src="ajax-loader.gif" />
<img src="/images/ajax-loader" />
<img src="/images/ajax-loader.gif.bak" />
<img src="/images/not-ajax-loader.gif" />
<img src="/more/images/ajax-loader.gif" />
<img src="/cool_images/ajax-loader.gif" />
<img src="http://othersite.com/images/ajax-loader.gif" />
3 changes: 2 additions & 1 deletion test/fixtures/views/media/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Relative path -->
<img src="/oops/../images/ajax-loader.gif" />
<img src="../images/ajax-loader.gif" />
<img src="../oops/../images/ajax-loader.gif" />
<img src="../oops/../images/oops/../ajax-loader.gif" />

<!-- Delimiters -->
<img src="/images/ajax-loader.gif" /><img src="/images/ajax-loader.gif" />
Expand All @@ -20,6 +20,7 @@
<img src="ajax-loader.gif" />
<img src="/images/ajax-loader" />
<img src="/images/ajax-loader.gif.bak" />
<img src="/images/not-ajax-loader.gif" />
<img src="images/ajax-loader.gif" />
<img src="/more/images/ajax-loader.gif" />
<img src="/cool_images/ajax-loader.gif" />
Expand Down

0 comments on commit 7d91db8

Please sign in to comment.