Skip to content

Commit

Permalink
fix(compiler-sfc): should not transform external asset url with
Browse files Browse the repository at this point in the history
includeAbsolute: true
  • Loading branch information
yyx990803 committed May 6, 2020
1 parent 037fa07 commit d662118
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */))
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ describe('compiler sfc: transform asset url', () => {

test('with includeAbsolute: true', () => {
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
}
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-sfc/src/templateTransformAssetUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d662118

Please sign in to comment.