Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'`
}
},
},
],
})