fix(compiler-sfc): should not transform external asset url with

includeAbsolute: true
This commit is contained in:
Evan You 2020-05-06 09:40:55 -04:00
parent 037fa07113
commit d66211849c
3 changed files with 7 additions and 3 deletions

View File

@ -59,7 +59,8 @@ import _imports_1 from '/bar.png'
export function render(_ctx, _cache) { export function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_Fragment, null, [ return (_openBlock(), _createBlock(_Fragment, null, [
_createVNode(\\"img\\", { src: _imports_0 }), _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 */)) ], 64 /* STABLE_FRAGMENT */))
}" }"
`; `;

View File

@ -70,7 +70,9 @@ describe('compiler sfc: transform asset url', () => {
test('with includeAbsolute: true', () => { test('with includeAbsolute: true', () => {
const { code } = compileWithAssetUrls( const { code } = compileWithAssetUrls(
`<img src="./bar.png"></img>` + `<img src="/bar.png"></img>`, `<img src="./bar.png"/>` +
`<img src="/bar.png"/>` +
`<img src="https://foo.bar/baz.png"/>`,
{ {
includeAbsolute: true includeAbsolute: true
} }

View File

@ -7,7 +7,7 @@ import {
SourceLocation, SourceLocation,
TransformContext TransformContext
} from '@vue/compiler-core' } from '@vue/compiler-core'
import { isRelativeUrl, parseUrl } from './templateUtils' import { isRelativeUrl, parseUrl, isExternalUrl } from './templateUtils'
import { isArray } from '@vue/shared' import { isArray } from '@vue/shared'
export interface AssetURLTagConfig { export interface AssetURLTagConfig {
@ -98,6 +98,7 @@ export const transformAssetUrl: NodeTransform = (
attr.type !== NodeTypes.ATTRIBUTE || attr.type !== NodeTypes.ATTRIBUTE ||
!assetAttrs.includes(attr.name) || !assetAttrs.includes(attr.name) ||
!attr.value || !attr.value ||
isExternalUrl(attr.value.content) ||
(!options.includeAbsolute && !isRelativeUrl(attr.value.content)) (!options.includeAbsolute && !isRelativeUrl(attr.value.content))
) { ) {
return return