fix(compiler-sfc): asset url transform should ignore direct hash urls
This commit is contained in:
parent
8b9ee5798e
commit
5ddd9d2417
@ -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"`)
|
||||
})
|
||||
})
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user