From ec7099813cb43a27ff86abccbe06e5b21d297f91 Mon Sep 17 00:00:00 2001 From: Jeff Tian Date: Thu, 31 Aug 2023 17:21:05 +0800 Subject: [PATCH] refactor(https://github.com/vuejs/vitepress/issues/2596): use isRelativeUrl and template string --- .../compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts | 2 +- packages/compiler-sfc/src/template/transformAssetUrl.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts index 99de8d92ebd..4dcfbbd1455 100644 --- a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts +++ b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts @@ -169,7 +169,7 @@ describe('compiler sfc: transform asset url', () => { test('transform with stringify with space in absolute filename', () => { const { code } = compileWithAssetUrls( - `
` + `` + `
`, + `
`, { includeAbsolute: true }, diff --git a/packages/compiler-sfc/src/template/transformAssetUrl.ts b/packages/compiler-sfc/src/template/transformAssetUrl.ts index 265b3e9552b..3c5b9f93ca4 100644 --- a/packages/compiler-sfc/src/template/transformAssetUrl.ts +++ b/packages/compiler-sfc/src/template/transformAssetUrl.ts @@ -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) }) }