]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): asset url transform should ignore direct hash urls
authorEvan You <yyx990803@gmail.com>
Fri, 29 May 2020 14:20:57 +0000 (10:20 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 29 May 2020 14:20:57 +0000 (10:20 -0400)
packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts
packages/compiler-sfc/src/templateTransformAssetUrl.ts

index 91ea19dcaeca4e47914bcf0dfd471d87b3edb1eb..71be0e5275564403603a6bf334b961c6e3374b70 100644 (file)
@@ -79,4 +79,18 @@ describe('compiler sfc: transform asset url', () => {
     )
     expect(code).toMatchSnapshot()
   })
+
+  // vitejs/vite#298
+  test('should not transform hash fragments', () => {
+    const { code } = compileWithAssetUrls(
+      `<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+        <defs>
+          <circle id="myCircle" cx="0" cy="0" r="5" />
+        </defs>
+        <use x="5" y="5" xlink:href="#myCircle" />
+      </svg>`
+    )
+    // should not remove it
+    expect(code).toMatch(`"xlink:href": "#myCircle"`)
+  })
 })
index 3ca2984e7eadeced492f3a30baacc5f79056ba7a..a526d9a9c4291a5e97fad69c569c07e9b9b94ffa 100644 (file)
@@ -99,6 +99,7 @@ export const transformAssetUrl: NodeTransform = (
         !assetAttrs.includes(attr.name) ||
         !attr.value ||
         isExternalUrl(attr.value.content) ||
+        attr.value.content[0] === '#' ||
         (!options.includeAbsolute && !isRelativeUrl(attr.value.content))
       ) {
         return