From fa26713e198273d02a7cab06fbb013ffafe17da4 Mon Sep 17 00:00:00 2001 From: Tim Hettler Date: Sun, 16 Nov 2014 14:48:08 +0700 Subject: [PATCH] Close #491 PR: Srcset regex should match any valid image candidate string. --- lib/fileprocessor.js | 2 +- test/test-fileprocessor.js | 42 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/fileprocessor.js b/lib/fileprocessor.js index 00fff6b..46edb7e 100644 --- a/lib/fileprocessor.js +++ b/lib/fileprocessor.js @@ -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' ], [ diff --git a/test/test-fileprocessor.js b/test/test-fileprocessor.js index f6d3a8d..e948757 100644 --- a/test/test-fileprocessor.js +++ b/test/test-fileprocessor.js @@ -429,15 +429,53 @@ describe('FileProcessor', function () { }); it('should replace img reference in srcset', function () { + var content = ''; + var replaced = fp.replaceWithRevved(content, ['app']); + assert.equal(replaced, ''); + }); + + it('should replace img reference in srcset with pixel density descriptor', function () { var content = ''; var replaced = fp.replaceWithRevved(content, ['app']); assert.equal(replaced, ''); + }); - content = ''; - replaced = fp.replaceWithRevved(content, ['app']); + it('should replace img reference in srcset with width descriptor', function () { + var content = ''; + var replaced = fp.replaceWithRevved(content, ['app']); + assert.equal(replaced, ''); + }); + + it('should replace img reference in srcset with pixel density descriptor and with width descriptor', function () { + var content = ''; + var replaced = fp.replaceWithRevved(content, ['app']); + assert.equal(replaced, ''); + }); + + it('should replace source reference in srcset', function () { + var content = ''; + var replaced = fp.replaceWithRevved(content, ['app']); + assert.equal(replaced, ''); + }); + + it('should replace source reference in srcset with pixel density descriptor', function () { + var content = ''; + var replaced = fp.replaceWithRevved(content, ['app']); assert.equal(replaced, ''); }); + it('should replace source reference in srcset with width descriptor', function () { + var content = ''; + var replaced = fp.replaceWithRevved(content, ['app']); + assert.equal(replaced, ''); + }); + + it('should replace source reference in srcset with pixel density descriptor and with width descriptor', function () { + var content = ''; + var replaced = fp.replaceWithRevved(content, ['app']); + assert.equal(replaced, ''); + }); + it('should replace svg src reference with revved version for img tag', function () { var content = ''; var replaced = fp.replaceWithRevved(content, ['app']);