Skip to content

Commit 96084d6

Browse files
committed
fix(data-uri): only match ids starting with data: (#18241)
1 parent eae00b5 commit 96084d6

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

packages/vite/src/node/plugins/dataUri.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function dataURIPlugin(): Plugin {
2222
},
2323

2424
resolveId(id) {
25-
if (!dataUriRE.test(id)) {
25+
if (!id.trimStart().startsWith('data:')) {
2626
return
2727
}
2828

playground/data-uri/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="plain"></div>
22
<div class="base64"></div>
3+
<div class="comma"></div>
34

45
<script type="module">
56
import msg from "data:text/javascript, export default 'hi'"
@@ -8,6 +9,9 @@
89
import base64Msg from 'data:text/javascript;base64, ZXhwb3J0IGRlZmF1bHQgJ2hpJw=='
910
text('.base64', base64Msg)
1011

12+
import { comma } from 'comma/foo?number=1,2,3'
13+
text('.comma', comma)
14+
1115
function text(el, text) {
1216
document.querySelector(el).textContent = text
1317
}

playground/data-uri/vite.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { defineConfig } from 'vite'
2+
3+
export default defineConfig({
4+
plugins: [
5+
{
6+
name: 'post-plugin',
7+
enforce: 'post',
8+
resolveId(id) {
9+
if (id.replace(/\?.*$/, '') === 'comma/foo') {
10+
return id
11+
}
12+
},
13+
load(id) {
14+
if (id.replace(/\?.*$/, '') === 'comma/foo') {
15+
return `export const comma = 'hi'`
16+
}
17+
},
18+
},
19+
],
20+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy