Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support space contained in the filename for asset #8752

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 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,34 @@ 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'`)
})

test('transform with stringify with space in relative 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'`)
})
})
8 changes: 7 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,13 @@ function getImportsExpressionExp(
loc,
ConstantTypes.CAN_STRINGIFY
)
context.imports.push({ exp, path })

// We need to ensure the path is not encoded (to %2F),
// so we decode it back in case it is encoded
context.imports.push({
exp,
path: decodeURIComponent(path)
})
}

if (!hash) {
Expand Down