From d66211849ca174c4458b59d3df5569730ee224f6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 6 May 2020 09:40:55 -0400 Subject: [PATCH] fix(compiler-sfc): should not transform external asset url with includeAbsolute: true --- .../__snapshots__/templateTransformAssetUrl.spec.ts.snap | 3 ++- .../compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts | 4 +++- packages/compiler-sfc/src/templateTransformAssetUrl.ts | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap index 3373e885ff8..998eeae568d 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap @@ -59,7 +59,8 @@ import _imports_1 from '/bar.png' export function render(_ctx, _cache) { return (_openBlock(), _createBlock(_Fragment, null, [ _createVNode(\\"img\\", { src: _imports_0 }), - _createVNode(\\"img\\", { src: _imports_1 }) + _createVNode(\\"img\\", { src: _imports_1 }), + _createVNode(\\"img\\", { src: \\"https://foo.bar/baz.png\\" }) ], 64 /* STABLE_FRAGMENT */)) }" `; diff --git a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts index 1102690fdcf..91ea19dcaec 100644 --- a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts +++ b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts @@ -70,7 +70,9 @@ describe('compiler sfc: transform asset url', () => { test('with includeAbsolute: true', () => { const { code } = compileWithAssetUrls( - `` + ``, + `` + + `` + + ``, { includeAbsolute: true } diff --git a/packages/compiler-sfc/src/templateTransformAssetUrl.ts b/packages/compiler-sfc/src/templateTransformAssetUrl.ts index 0b7c9175f4d..3ca2984e7ea 100644 --- a/packages/compiler-sfc/src/templateTransformAssetUrl.ts +++ b/packages/compiler-sfc/src/templateTransformAssetUrl.ts @@ -7,7 +7,7 @@ import { SourceLocation, TransformContext } from '@vue/compiler-core' -import { isRelativeUrl, parseUrl } from './templateUtils' +import { isRelativeUrl, parseUrl, isExternalUrl } from './templateUtils' import { isArray } from '@vue/shared' export interface AssetURLTagConfig { @@ -98,6 +98,7 @@ export const transformAssetUrl: NodeTransform = ( attr.type !== NodeTypes.ATTRIBUTE || !assetAttrs.includes(attr.name) || !attr.value || + isExternalUrl(attr.value.content) || (!options.includeAbsolute && !isRelativeUrl(attr.value.content)) ) { return