Skip to content

Commit

Permalink
fix(compiler-sfc): asset url transform should ignore direct hash urls
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 29, 2020
1 parent 8b9ee57 commit 5ddd9d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"`)
})
})
1 change: 1 addition & 0 deletions packages/compiler-sfc/src/templateTransformAssetUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ddd9d2

Please sign in to comment.