@@ -150,6 +150,29 @@ describe('compiler sfc: transform asset url', () => {
150150 expect ( code ) . toContain ( `import _imports_0 from './foo%.png'` )
151151 } )
152152
153+ test ( 'should not transform hash fragments on <image>' , ( ) => {
154+ // `<image href="#...">` is an in-document fragment reference to another
155+ // SVG element (like `<use>`), not a Node.js subpath import specifier.
156+ const { code } = compileWithAssetUrls (
157+ `<svg><image href="#" /><image href="#myClip" /></svg>` ,
158+ { includeAbsolute : true } ,
159+ )
160+ expect ( code ) . toContain ( `href: "#"` )
161+ expect ( code ) . toContain ( `href: "#myClip"` )
162+ expect ( code ) . not . toContain ( `from '#'` )
163+ expect ( code ) . not . toContain ( `from '#myClip'` )
164+ } )
165+
166+ test ( 'should not transform bare `#` value into an import' , ( ) => {
167+ // A bare `#` is never a valid module specifier and should always be left
168+ // untouched, even on tags that otherwise support subpath imports.
169+ const { code } = compileWithAssetUrls ( `<img src="#" />` , {
170+ includeAbsolute : true ,
171+ } )
172+ expect ( code ) . toContain ( `src: "#"` )
173+ expect ( code ) . not . toContain ( `from '#'` )
174+ } )
175+
153176 test ( 'should allow for full base URLs, with paths' , ( ) => {
154177 const { code } = compileWithAssetUrls ( `<img src="./logo.png" />` , {
155178 base : 'http://localhost:3000/src/' ,
0 commit comments