From a941fb08f7ca642596f7e098307e972ab5b8f575 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 15 Oct 2015 10:17:14 -0700 Subject: [PATCH] =?UTF-8?q?fix(style=5Fcompiler):=20don=E2=80=99t=20resolv?= =?UTF-8?q?e=20absolute=20urls=20that=20start=20with=20a=20`/`=20during=20?= =?UTF-8?q?compilation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4763 --- modules/angular2/src/core/compiler/style_url_resolver.ts | 4 ++-- .../angular2/test/core/compiler/style_url_resolver_spec.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/angular2/src/core/compiler/style_url_resolver.ts b/modules/angular2/src/core/compiler/style_url_resolver.ts index a95352392f..70b9fee499 100644 --- a/modules/angular2/src/core/compiler/style_url_resolver.ts +++ b/modules/angular2/src/core/compiler/style_url_resolver.ts @@ -15,7 +15,7 @@ export class StyleWithImports { } export function isStyleUrlResolvable(url: string): boolean { - if (isBlank(url) || url.length === 0) return false; + if (isBlank(url) || url.length === 0 || url[0] == '/') return false; var schemeMatch = RegExpWrapper.firstMatch(_urlWithSchemaRe, url); return isBlank(schemeMatch) || schemeMatch[1] == 'package'; } @@ -42,4 +42,4 @@ export function extractStyleUrls(resolver: UrlResolver, baseUrl: string, cssText var _cssImportRe = /@import\s+(?:url\()?\s*(?:(?:['"]([^'"]*))|([^;\)\s]*))[^;]*;?/g; // TODO: can't use /^[^:/?#.]+:/g due to clang-format bug: // https://github.com/angular/angular/issues/4596 -var _urlWithSchemaRe = /^['"]?([a-zA-Z\-\+\.]+):/g; \ No newline at end of file +var _urlWithSchemaRe = /^([a-zA-Z\-\+\.]+):/g; diff --git a/modules/angular2/test/core/compiler/style_url_resolver_spec.ts b/modules/angular2/test/core/compiler/style_url_resolver_spec.ts index edd7b4f562..ba0bba5d89 100644 --- a/modules/angular2/test/core/compiler/style_url_resolver_spec.ts +++ b/modules/angular2/test/core/compiler/style_url_resolver_spec.ts @@ -96,6 +96,11 @@ export function main() { it('should not resolve urls with other schema', () => { expect(isStyleUrlResolvable('http://otherurl')).toBe(false); }); + + it('should not resolve urls with absolute paths', () => { + expect(isStyleUrlResolvable('/otherurl')).toBe(false); + expect(isStyleUrlResolvable('//otherurl')).toBe(false); + }); }); }