Skip to content

Commit

Permalink
refactor(vuejs/vitepress#2596): use isRelativeUrl and template string
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff-Tian committed Aug 31, 2023
1 parent 45c2de9 commit ec70998
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('compiler sfc: transform asset url', () => {

test('transform with stringify with space in absolute filename', () => {
const { code } = compileWithAssetUrls(
`<div>` + `<img src="/foo bar.png"/>` + `</div>`,
`<div><img src="/foo bar.png"/></div>`,
{
includeAbsolute: true
},
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-sfc/src/template/transformAssetUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ function getImportsExpressionExp(
ConstantTypes.CAN_STRINGIFY
)
// 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
// In this case 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: path && path[0] === '/' ? decodeURIComponent(path) : path
path: isRelativeUrl(path) ? path : decodeURIComponent(path)
})
}

Expand Down

0 comments on commit ec70998

Please sign in to comment.