fix(data-uri): only match ids starting with data: (#18241)

This commit is contained in:
翠 / green 2024-09-30 17:57:36 +09:00 committed by sapphi-red
parent eae00b561e
commit 96084d6e75
No known key found for this signature in database
GPG Key ID: B5533BC1E6C4ED51
3 changed files with 25 additions and 1 deletions

View File

@ -22,7 +22,7 @@ export function dataURIPlugin(): Plugin {
},
resolveId(id) {
if (!dataUriRE.test(id)) {
if (!id.trimStart().startsWith('data:')) {
return
}

View File

@ -1,5 +1,6 @@
<div class="plain"></div>
<div class="base64"></div>
<div class="comma"></div>
<script type="module">
import msg from "data:text/javascript, export default 'hi'"
@ -8,6 +9,9 @@
import base64Msg from 'data:text/javascript;base64, ZXhwb3J0IGRlZmF1bHQgJ2hpJw=='
text('.base64', base64Msg)
import { comma } from 'comma/foo?number=1,2,3'
text('.comma', comma)
function text(el, text) {
document.querySelector(el).textContent = text
}

View File

@ -0,0 +1,20 @@
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
{
name: 'post-plugin',
enforce: 'post',
resolveId(id) {
if (id.replace(/\?.*$/, '') === 'comma/foo') {
return id
}
},
load(id) {
if (id.replace(/\?.*$/, '') === 'comma/foo') {
return `export const comma = 'hi'`
}
},
},
],
})