Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): error when using protocol-relativ…
Browse files Browse the repository at this point in the history
…e url

Fixes #12648
  • Loading branch information
alan-agius4 authored and Keen Yee Liau committed Oct 23, 2018
1 parent 515553f commit 22dc791
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export default postcss.plugin('postcss-cli-resources', (options: PostcssCliResou
const dedupeSlashes = (url: string) => url.replace(/\/\/+/g, '/');

const process = async (inputUrl: string, context: string, resourceCache: Map<string, string>) => {
// If root-relative or absolute, leave as is
if (inputUrl.match(/^(?:\w+:\/\/|data:|chrome:|#)/)) {
// If root-relative, absolute or protocol relative url, leave as is
if (/^((?:\w+:)?\/\/|data:|chrome:|#)/.test(inputUrl)) {
return inputUrl;
}

// If starts with a caret, remove and return remainder
// this supports bypassing asset processing
if (inputUrl.startsWith('^')) {
Expand All @@ -74,7 +75,7 @@ export default postcss.plugin('postcss-cli-resources', (options: PostcssCliResou
inputUrl = inputUrl.substr(1);
}

if (inputUrl.startsWith('/') && !inputUrl.startsWith('//')) {
if (inputUrl.startsWith('/')) {
let outputUrl = '';
if (deployUrl.match(/:\/\//) || deployUrl.startsWith('/')) {
// If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,25 @@ describe('Browser Builder styles', () => {
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
).toPromise().then(done, done.fail);
});

it('supports Protocol-relative Url', (done) => {
host.writeMultipleFiles({
'src/styles.css': `
body {
background-image: url('//cdn.com/classic-bg.jpg');
}
`,
});

const overrides = { extractCss: true, optimization: true };
runTargetSpec(host, browserTargetSpec, overrides).pipe(
tap((buildEvent) => {
expect(buildEvent.success).toBe(true);

const filePath = './dist/styles.css';
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(filePath)));
expect(content).toContain('background-image:url(//cdn.com/classic-bg.jpg)');
}),
).toPromise().then(done, done.fail);
});
});

0 comments on commit 22dc791

Please sign in to comment.