Skip to content

Commit

Permalink
fix(data-uri): only match ids starting with data: (#18241)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Sep 30, 2024
1 parent b916ab6 commit ec0efe8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/dataUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function dataURIPlugin(): Plugin {
},

resolveId(id) {
if (!dataUriRE.test(id)) {
if (!id.trimStart().startsWith('data:')) {
return
}

Expand Down
4 changes: 4 additions & 0 deletions playground/data-uri/index.html
Original file line number Diff line number Diff line change
@@ -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'"
Expand All @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions playground/data-uri/vite.config.js
Original file line number Diff line number Diff line change
@@ -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'`
}
},
},
],
})

0 comments on commit ec0efe8

Please sign in to comment.