]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): externalRE support automatic http/https prefix url pattern (#4922)
authorzisasign <zephyrisalive@gmail.com>
Mon, 15 Nov 2021 02:37:50 +0000 (10:37 +0800)
committerGitHub <noreply@github.com>
Mon, 15 Nov 2021 02:37:50 +0000 (21:37 -0500)
fix #4920

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

index 753f3f9a5247608d9ab75f9d22d1d39f4d1ddc95..37545d772d3eec1cb9e92c315a70d51b369be871 100644 (file)
@@ -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 */))
@@ -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 */))
 }"
 `;
index d07b92266860dd0fb85cbe4c6e329d245c9e4ea3..18e2cb5e98e0f40790424071a120052c79ecdf9a 100644 (file)
@@ -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"/>
                `)
@@ -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
       }
index 95bf619be5f389cb265776e860c7f73866a78ac3..a509657332a7ee8780a529a687a8345c2de9930e 100644 (file)
@@ -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', () => {
index b1befd927e23d052e7491673ffe77e2962a4ab3b..3f4cb8f6caa450140d2fa29a7ded18c8997d66ad 100644 (file)
@@ -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)
 }