Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Close #491 PR: Srcset regex should match any valid image candidate st…
Browse files Browse the repository at this point in the history
…ring.
  • Loading branch information
timhettler authored and sindresorhus committed Nov 16, 2014
1 parent 2e54488 commit fa26713
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var _defaultPatterns = {
'Update the HTML with the new image filenames for src links'
],
[
/<(?:img|source)[^\>]*[^\>\S]+srcset=['"]([^"'\s]+)(?:\s\d[mx])["']/gm,
/<(?:img|source)[^\>]*[^\>\S]+srcset=['"]([^"'\s]+)\s*?(?:\s\d*?[w])?(?:\s\d*?[x])?\s*?["']/gm,
'Update the HTML with the new image filenames for srcset links'
],
[
Expand Down
42 changes: 40 additions & 2 deletions test/test-fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,53 @@ describe('FileProcessor', function () {
});

it('should replace img reference in srcset', function () {
var content = '<img srcset="image.png" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img srcset="' + filemapping['app/image.png'] + '" />');
});

it('should replace img reference in srcset with pixel density descriptor', function () {
var content = '<img srcset="image@2x.png 2x" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img srcset="' + filemapping['app/image@2x.png'] + ' 2x" />');
});

content = '<source srcset="image@2x.png 2x" />';
replaced = fp.replaceWithRevved(content, ['app']);
it('should replace img reference in srcset with width descriptor', function () {
var content = '<img srcset="image.png 200w" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img srcset="' + filemapping['app/image.png'] + ' 200w" />');
});

it('should replace img reference in srcset with pixel density descriptor and with width descriptor', function () {
var content = '<img srcset="image.png 200w 2x" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img srcset="' + filemapping['app/image.png'] + ' 200w 2x" />');
});

it('should replace source reference in srcset', function () {
var content = '<source srcset="image.png" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<source srcset="' + filemapping['app/image.png'] + '" />');
});

it('should replace source reference in srcset with pixel density descriptor', function () {
var content = '<source srcset="image@2x.png 2x" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<source srcset="' + filemapping['app/image@2x.png'] + ' 2x" />');
});

it('should replace source reference in srcset with width descriptor', function () {
var content = '<source srcset="image.png 200w" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<source srcset="' + filemapping['app/image.png'] + ' 200w" />');
});

it('should replace source reference in srcset with pixel density descriptor and with width descriptor', function () {
var content = '<source srcset="image.png 200w 2x" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<source srcset="' + filemapping['app/image.png'] + ' 200w 2x" />');
});

it('should replace svg src reference with revved version for img tag', function () {
var content = '<img src="image.svg#symbol">';
var replaced = fp.replaceWithRevved(content, ['app']);
Expand Down

0 comments on commit fa26713

Please sign in to comment.