fix(style_url_resolver): fix data: url resolution
This commit is contained in:
parent
192cf9ddf5
commit
73b7d99dc4
|
@ -263,7 +263,10 @@ export class RegExpWrapper {
|
|||
regExp.lastIndex = 0;
|
||||
return regExp.exec(input);
|
||||
}
|
||||
static test(regExp: RegExp, input: string): boolean { return regExp.test(input); }
|
||||
static test(regExp: RegExp, input: string): boolean {
|
||||
regExp.lastIndex = 0;
|
||||
return regExp.test(input);
|
||||
}
|
||||
static matcher(regExp: RegExp, input: string): {
|
||||
re: RegExp;
|
||||
input: string
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// https://github.com/webcomponents/webcomponentsjs/blob/master/src/HTMLImports/path.js
|
||||
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {RegExp, StringWrapper} from 'angular2/src/facade/lang';
|
||||
import {RegExp, RegExpWrapper, StringWrapper} from 'angular2/src/facade/lang';
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,12 @@ export class StyleUrlResolver {
|
|||
_replaceUrls(cssText: string, re: RegExp, baseUrl: string) {
|
||||
return StringWrapper.replaceAllMapped(cssText, re, (m) => {
|
||||
var pre = m[1];
|
||||
var url = StringWrapper.replaceAll(m[2], _quoteRe, '');
|
||||
var originalUrl = m[2];
|
||||
if (RegExpWrapper.test(_dataUrlRe, originalUrl)) {
|
||||
// Do not attempt to resolve data: URLs
|
||||
return m[0];
|
||||
}
|
||||
var url = StringWrapper.replaceAll(originalUrl, _quoteRe, '');
|
||||
var post = m[3];
|
||||
|
||||
var resolvedUrl = this._resolver.resolve(baseUrl, url);
|
||||
|
@ -34,3 +39,4 @@ export class StyleUrlResolver {
|
|||
var _cssUrlRe = /(url\()([^)]*)(\))/g;
|
||||
var _cssImportRe = /(@import[\s]+(?!url\())['"]([^'"]*)['"](.*;)/g;
|
||||
var _quoteRe = /['"]/g;
|
||||
var _dataUrlRe = /^['"]?data:/g;
|
||||
|
|
|
@ -24,6 +24,14 @@ export function main() {
|
|||
|
||||
expect(indexes).toEqual([1, 4, 8, 9]);
|
||||
});
|
||||
|
||||
it('should reset before it is reused', () => {
|
||||
var re = /^['"]/g;
|
||||
var str = "'";
|
||||
expect(RegExpWrapper.test(re, str)).toEqual(true);
|
||||
// If not reset, the second attempt to test results in false
|
||||
expect(RegExpWrapper.test(re, str)).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('const', () => {
|
||||
|
|
|
@ -70,5 +70,26 @@ export function main() {
|
|||
var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
|
||||
expect(resolvedCss).toEqual(expectedCss);
|
||||
});
|
||||
|
||||
it('should not strip quotes from inlined SVG styles', () => {
|
||||
var css = `
|
||||
.selector {
|
||||
background:rgb(55,71,79) url('data:image/svg+xml;utf8,<?xml version="1.0"?>');
|
||||
background:rgb(55,71,79) url("data:image/svg+xml;utf8,<?xml version='1.0'?>");
|
||||
background:rgb(55,71,79) url("/some/data:image");
|
||||
}
|
||||
`;
|
||||
|
||||
var expectedCss = `
|
||||
.selector {
|
||||
background:rgb(55,71,79) url('data:image/svg+xml;utf8,<?xml version="1.0"?>');
|
||||
background:rgb(55,71,79) url("data:image/svg+xml;utf8,<?xml version='1.0'?>");
|
||||
background:rgb(55,71,79) url('http://ng.io/some/data:image');
|
||||
}
|
||||
`;
|
||||
|
||||
var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
|
||||
expect(resolvedCss).toEqual(expectedCss);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue