Skip to content

Commit d662118

Browse files
committed
fix(compiler-sfc): should not transform external asset url with
includeAbsolute: true
1 parent 037fa07 commit d662118

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ import _imports_1 from '/bar.png'
5959
export function render(_ctx, _cache) {
6060
return (_openBlock(), _createBlock(_Fragment, null, [
6161
_createVNode(\\"img\\", { src: _imports_0 }),
62-
_createVNode(\\"img\\", { src: _imports_1 })
62+
_createVNode(\\"img\\", { src: _imports_1 }),
63+
_createVNode(\\"img\\", { src: \\"https://foo.bar/baz.png\\" })
6364
], 64 /* STABLE_FRAGMENT */))
6465
}"
6566
`;

packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ describe('compiler sfc: transform asset url', () => {
7070

7171
test('with includeAbsolute: true', () => {
7272
const { code } = compileWithAssetUrls(
73-
`<img src="./bar.png"></img>` + `<img src="/bar.png"></img>`,
73+
`<img src="./bar.png"/>` +
74+
`<img src="/bar.png"/>` +
75+
`<img src="https://foo.bar/baz.png"/>`,
7476
{
7577
includeAbsolute: true
7678
}

packages/compiler-sfc/src/templateTransformAssetUrl.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
SourceLocation,
88
TransformContext
99
} from '@vue/compiler-core'
10-
import { isRelativeUrl, parseUrl } from './templateUtils'
10+
import { isRelativeUrl, parseUrl, isExternalUrl } from './templateUtils'
1111
import { isArray } from '@vue/shared'
1212

1313
export interface AssetURLTagConfig {
@@ -98,6 +98,7 @@ export const transformAssetUrl: NodeTransform = (
9898
attr.type !== NodeTypes.ATTRIBUTE ||
9999
!assetAttrs.includes(attr.name) ||
100100
!attr.value ||
101+
isExternalUrl(attr.value.content) ||
101102
(!options.includeAbsolute && !isRelativeUrl(attr.value.content))
102103
) {
103104
return

0 commit comments

Comments
 (0)