X Tutup
Skip to content

Commit a941fb0

Browse files
committed
fix(style_compiler): don’t resolve absolute urls that start with a / during compilation
Closes #4763
1 parent cec8b58 commit a941fb0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

modules/angular2/src/core/compiler/style_url_resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class StyleWithImports {
1515
}
1616

1717
export function isStyleUrlResolvable(url: string): boolean {
18-
if (isBlank(url) || url.length === 0) return false;
18+
if (isBlank(url) || url.length === 0 || url[0] == '/') return false;
1919
var schemeMatch = RegExpWrapper.firstMatch(_urlWithSchemaRe, url);
2020
return isBlank(schemeMatch) || schemeMatch[1] == 'package';
2121
}
@@ -42,4 +42,4 @@ export function extractStyleUrls(resolver: UrlResolver, baseUrl: string, cssText
4242
var _cssImportRe = /@import\s+(?:url\()?\s*(?:(?:['"]([^'"]*))|([^;\)\s]*))[^;]*;?/g;
4343
// TODO: can't use /^[^:/?#.]+:/g due to clang-format bug:
4444
// https://github.com/angular/angular/issues/4596
45-
var _urlWithSchemaRe = /^['"]?([a-zA-Z\-\+\.]+):/g;
45+
var _urlWithSchemaRe = /^([a-zA-Z\-\+\.]+):/g;

modules/angular2/test/core/compiler/style_url_resolver_spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ export function main() {
9696

9797
it('should not resolve urls with other schema',
9898
() => { expect(isStyleUrlResolvable('http://otherurl')).toBe(false); });
99+
100+
it('should not resolve urls with absolute paths', () => {
101+
expect(isStyleUrlResolvable('/otherurl')).toBe(false);
102+
expect(isStyleUrlResolvable('//otherurl')).toBe(false);
103+
});
99104
});
100105
}
101106

0 commit comments

Comments
 (0)
X Tutup