Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): externalRE support automatic http/https prefix url… #4922

Merged
merged 1 commit into from Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -67,6 +67,7 @@ export function render(_ctx, _cache) {
_createElementVNode(\\"img\\", { src: _imports_1 }),
_createElementVNode(\\"img\\", { src: _imports_1 }),
_createElementVNode(\\"img\\", { src: \\"http://example.com/fixtures/logo.png\\" }),
_createElementVNode(\\"img\\", { src: \\"//example.com/fixtures/logo.png\\" }),
_createElementVNode(\\"img\\", { src: \\"/fixtures/logo.png\\" }),
_createElementVNode(\\"img\\", { src: \\"data:image/png;base64,i\\" })
], 64 /* STABLE_FRAGMENT */))
Expand Down Expand Up @@ -99,7 +100,8 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(_Fragment, null, [
_createElementVNode(\\"img\\", { src: _imports_0 }),
_createElementVNode(\\"img\\", { src: _imports_1 }),
_createElementVNode(\\"img\\", { src: \\"https://foo.bar/baz.png\\" })
_createElementVNode(\\"img\\", { src: \\"https://foo.bar/baz.png\\" }),
_createElementVNode(\\"img\\", { src: \\"//foo.bar/baz.png\\" })
], 64 /* STABLE_FRAGMENT */))
}"
`;
Expand Up @@ -29,6 +29,7 @@ describe('compiler sfc: transform asset url', () => {
<img src="~fixtures/logo.png"/>
<img src="~/fixtures/logo.png"/>
<img src="http://example.com/fixtures/logo.png"/>
<img src="//example.com/fixtures/logo.png"/>
<img src="/fixtures/logo.png"/>
<img src="data:image/png;base64,i"/>
`)
Expand Down Expand Up @@ -76,7 +77,8 @@ describe('compiler sfc: transform asset url', () => {
const { code } = compileWithAssetUrls(
`<img src="./bar.png"/>` +
`<img src="/bar.png"/>` +
`<img src="https://foo.bar/baz.png"/>`,
`<img src="https://foo.bar/baz.png"/>` +
`<img src="//foo.bar/baz.png"/>`,
{
includeAbsolute: true
}
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler-sfc/__tests__/templateUtils.spec.ts
Expand Up @@ -36,6 +36,12 @@ describe('compiler sfc:templateUtils isExternalUrl', () => {
const result = isExternalUrl(url)
expect(result).toBe(true)
})

test('should return true when String starts with //', () => {
const url = '//vuejs.org/'
const result = isExternalUrl(url)
expect(result).toBe(true)
})
})

describe('compiler sfc:templateUtils isDataUrl', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/templateUtils.ts
Expand Up @@ -6,7 +6,7 @@ export function isRelativeUrl(url: string): boolean {
return firstChar === '.' || firstChar === '~' || firstChar === '@'
}

const externalRE = /^https?:\/\//
const externalRE = /^(https?:)?\/\//
export function isExternalUrl(url: string): boolean {
return externalRE.test(url)
}
Expand Down