Skip to content

Commit

Permalink
feat(vuejs/vitepress#2596): support space contained in the filename f…
Browse files Browse the repository at this point in the history
…or asset
  • Loading branch information
Jeff-Tian committed Jul 10, 2023
1 parent 788527e commit 09c6a20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,19 @@ describe('compiler sfc: transform asset url', () => {
expect(code).toMatch(`_createStaticVNode`)
expect(code).toMatchSnapshot()
})

test('transform with stringify with space in absolute filename', () => {
const { code } = compileWithAssetUrls(
`<div>` + `<img src="/foo bar.png"/>` + `</div>`,
{
includeAbsolute: true
},
{
hoistStatic: true,
transformHoist: stringifyStatic
}
)
expect(code).toMatch(`_createElementVNode`)
expect(code).toContain(`import _imports_0 from '/foo bar.png'`)
})
})
7 changes: 6 additions & 1 deletion packages/compiler-sfc/src/template/transformAssetUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ function getImportsExpressionExp(
loc,
ConstantTypes.CAN_STRINGIFY
)
context.imports.push({ exp, path })
// When path starts with /, for example, /foo/bar.png, it is an absolute file path
// In this case we need to ensure the path is not encoded
context.imports.push({
exp,
path: path && path[0] === '/' ? decodeURIComponent(path) : path
})
}

if (!hash) {
Expand Down

0 comments on commit 09c6a20

Please sign in to comment.