mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
fix: dont resolve imports with malformed URI (#16244)
This commit is contained in:
parent
a67f9f6945
commit
fbf69d5f6c
@ -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, {
|
||||
|
@ -389,11 +389,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`),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
BIN
playground/assets/asset/percent%.png
Normal file
BIN
playground/assets/asset/percent%.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 157 KiB |
@ -135,7 +135,7 @@
|
||||
<h2>Unicode URL</h2>
|
||||
<div>
|
||||
<code class="unicode-url"></code>
|
||||
<img src="./nested/テスト-測試-white space%25.png" />
|
||||
<img src="./nested/テスト-測試-white space.png" />
|
||||
</div>
|
||||
|
||||
<h2>Filename including single quote</h2>
|
||||
@ -143,11 +143,17 @@
|
||||
<code class="filename-including-single-quote"></code>
|
||||
</div>
|
||||
|
||||
<h2>Filename including percent</h2>
|
||||
<div>
|
||||
<code class="percent-url"></code>
|
||||
<img src="./asset/percent%25.png" />
|
||||
</div>
|
||||
|
||||
<h2>encodeURI for the address</h2>
|
||||
<div>
|
||||
<img
|
||||
class="encodeURI"
|
||||
src="./nested/%E3%83%86%E3%82%B9%E3%83%88-%E6%B8%AC%E8%A9%A6-white%20space%25.png"
|
||||
src="./nested/%E3%83%86%E3%82%B9%E3%83%88-%E6%B8%AC%E8%A9%A6-white%20space.png"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -447,12 +453,16 @@
|
||||
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)
|
||||
|
||||
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
Loading…
Reference in New Issue
Block a user