fix(StyleInliner): add support for url(url) format

This commit is contained in:
Victor Berchet 2015-02-26 10:26:31 +01:00
parent e3f4c60f46
commit 4d8d17ce3d
2 changed files with 7 additions and 4 deletions

View File

@ -118,11 +118,11 @@ export class StyleInliner {
// Extracts the url from an import rule, supported formats:
// - 'url' / "url",
// - url('url') / url("url")
// - url(url) / url('url') / url("url")
function _extractUrl(importRule: string): string {
var match = RegExpWrapper.firstMatch(_urlRe, importRule);
if (isBlank(match)) return null;
return match[1];
return isPresent(match[1]) ? match[1] : match[2];
}
// Extracts the media query from an import rule.
@ -140,5 +140,8 @@ function _wrapInMediaRule(css: string, query: string): string {
}
var _importRe = RegExpWrapper.create('@import\\s+([^;]+);');
var _urlRe = RegExpWrapper.create('(?:url\\(\\s*)?[\'"]([^\'"]+)[\'"]');
var _urlRe = RegExpWrapper.create(
'url\\(\\s*?[\'"]?([^\'")]+)[\'"]?|' + // url(url) or url('url') or url("url")
'[\'"]([^\'")]+)[\'"]' // "url" or 'url'
);
var _mediaQueryRe = RegExpWrapper.create('[\'"][^\'"]+[\'"]\\s*\\)?\\s*(.*)');

View File

@ -46,7 +46,7 @@ export function main() {
});
// TODO(vicb): fix the StyleInliner
xit('should support url([unquoted url]) in @import rules', (done) => {
it('should support url([unquoted url]) in @import rules', (done) => {
xhr.reply('http://base/one.css', '.one {}');
var css = '@import url(one.css);.main {}';
var loadedCss = inliner.inlineImports(css, 'http://base');