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

Fix image src attributes on minified html. #562

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _defaultPatterns = {
'Update the HTML with the new css filenames'
],
[
/<img[^\>]*[^\>\S]+src=['"]([^'"\)#]+)(#.+)?["']/gm,
/<img[^\>]*[^\>\S]+src=['"]([^'"#]+)(#[^'"]+)?["']/gm,
'Update the HTML with the new img filenames'
],
[
Expand Down
12 changes: 12 additions & 0 deletions test/test-fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ describe('FileProcessor', function () {
assert.equal(replaced, '<img src="' + filemapping['app/image.png'] + '">');
});

it('should replace two identical img references in the same line with revved versions', function () {
var content = '<img src="image.png"><img src="image.png">';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img src="' + filemapping['app/image.png'] + '"><img src="' + filemapping['app/image.png'] + '">');
});

it('should replace object data reference with revved version', function () {
var content = '<object type="image/svg+xml" data="image.svg">';
var replaced = fp.replaceWithRevved(content, ['app']);
Expand Down Expand Up @@ -479,6 +485,12 @@ describe('FileProcessor', function () {
assert.equal(replaced, '<img src="' + filemapping['app/image.svg'] + '#symbol">');
});

it('should replace two identical svg src references in a single line with revved version for img tag', function () {
var content = '<img src="image.svg#symbol"><img src="image.svg#symbol">';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img src="' + filemapping['app/image.svg'] + '#symbol"><img src="' + filemapping['app/image.svg'] + '#symbol">');
});

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