diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 4c940aa109b00a..6d758e04cd807c 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -40,7 +40,6 @@ import { joinUrlSegments, moduleListContains, normalizePath, - partialEncodeURIPath, prettifyUrl, removeImportQuery, removeTimestampQuery, @@ -594,9 +593,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { rewriteDone = true } if (!rewriteDone) { - const rewrittenUrl = JSON.stringify( - ssr ? url : partialEncodeURIPath(url), - ) + const rewrittenUrl = JSON.stringify(url) const s = isDynamicImport ? start : start - 1 const e = isDynamicImport ? end : end + 1 str().overwrite(s, e, rewrittenUrl, { diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts index 6fb337a9484bb6..fb00f0ac2041f8 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -369,11 +369,11 @@ test('?url import on css', async () => { describe('unicode url', () => { test('from js import', async () => { - const src = readFile('テスト-測試-white space%.js') + const src = readFile('テスト-測試-white space.js') expect(await page.textContent('.unicode-url')).toMatch( isBuild ? `data:text/javascript;base64,${Buffer.from(src).toString('base64')}` - : encodeURI(`/foo/bar/テスト-測試-white space%.js`), + : encodeURI(`/foo/bar/テスト-測試-white space.js`), ) }) }) diff --git a/playground/assets/asset/percent%.png b/playground/assets/asset/percent%.png new file mode 100644 index 00000000000000..b5e16ddc80b8ab Binary files /dev/null and b/playground/assets/asset/percent%.png differ diff --git a/playground/assets/index.html b/playground/assets/index.html index 80fbf14be8bc59..3180f2c966c00c 100644 --- a/playground/assets/index.html +++ b/playground/assets/index.html @@ -135,7 +135,7 @@

CSS url references

Unicode URL

- +

Filename including single quote

@@ -143,11 +143,17 @@

Filename including single quote

+

Filename including percent

+
+ + +
+

encodeURI for the address

@@ -442,12 +448,16 @@

assets in noscript

import fooUrl from './foo.js?url' text('.url', fooUrl) - import unicodeUrl from './テスト-測試-white space%.js?url' + import unicodeUrl from './テスト-測試-white space.js?url' text('.unicode-url', unicodeUrl) import filenameIncludingSingleQuoteUrl from "./nested/with-single'quote.png" text('.filename-including-single-quote', filenameIncludingSingleQuoteUrl) + // TODO: is not supported yet (https://github.com/vitejs/vite/pull/16243) + // import percentUrl from './asset/percent%25.png?url' + // text('.percent-url', percentUrl) + import cssUrl from './css/icons.css?url' text('.url-css', cssUrl) diff --git "a/playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space%.png" "b/playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.png" similarity index 100% rename from "playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space%.png" rename to "playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.png" diff --git "a/playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space%.js" "b/playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.js" similarity index 100% rename from "playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space%.js" rename to "playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.js"