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

Commit

Permalink
Merge pull request #340 from lukebussey/css-font-fix
Browse files Browse the repository at this point in the history
Modifying CSS RegEx to fix SVG fragment identifiers in font URIs
  • Loading branch information
addyosmani committed Apr 9, 2014
2 parents 195e594 + 96cef68 commit 4720e8d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _defaultPatterns = {
],
'css': [
/*jshint regexp:false */
[ /(?:src=|url\(\s*)['"]?([^'"\)\?]+)['"]?\s*\)?/gm,
[ /(?:src=|url\(\s*)['"]?([^'"\)(\?|#)]+)['"]?\s*\)?/gm,
'Update the CSS to reference our revved images'
]
]
Expand Down
26 changes: 26 additions & 0 deletions test/test-fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,32 @@ describe('FileProcessor', function() {

});

describe('font path', function() {
var content = '@font-face {\nfont-family:"icons";\nsrc:url("/styles/fonts/icons.eot");\nsrc:url("/styles/fonts/icons.eot#fragment") format("embedded-opentype"),\nurl("/styles/fonts/icons.woff") format("woff"),\nurl("/styles/fonts/icons.ttf") format("truetype"),\nurl("/styles/fonts/icons.svg#icons") format("svg");\nfont-weight:normal;\nfont-style:normal;\n}';
var filemapping = {
'build/styles/fonts/icons.eot': '/styles/fonts/icons.12345.eot',
'build/styles/fonts/icons.woff': '/styles/fonts/icons.12345.woff',
'build/styles/fonts/icons.ttf': '/styles/fonts/icons.12345.ttf',
'build/styles/fonts/icons.svg': '/styles/fonts/icons.12345.svg',
};

var revvedfinder = helpers.makeFinder(filemapping);

beforeEach(function() {
cp = new FileProcessor('css', revvedfinder);
});

it('should replace but ignore querystrings on revved files when found', function(){
var changed = cp.replaceWithRevved(content, ['build']);

assert.ok(changed.match(/\/styles\/fonts\/icons\.12345\.eot/));
assert.ok(changed.match(/\/styles\/fonts\/icons\.12345\.woff/));
assert.ok(changed.match(/\/styles\/fonts\/icons\.12345\.ttf/));
assert.ok(changed.match(/\/styles\/fonts\/icons\.12345\.svg/));
});

});


});
});

0 comments on commit 4720e8d

Please sign in to comment.