Skip to content

Commit 1f855dc

Browse files
authored
fix: port #15653 to v2 (#15657)
1 parent ea814d7 commit 1f855dc

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

packages/playground/fs-serve/__tests__/fs-serve.spec.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ describe('main', () => {
9797
})
9898

9999
test('denied', async () => {
100-
expect(await page.textContent('.unsafe-dotenv')).toBe('404')
100+
expect(await page.textContent('.unsafe-dotenv')).toBe('403')
101+
})
102+
103+
test('denied EnV casing', async () => {
104+
// It is 403 in case insensitive system, 404 in others
105+
const code = await page.textContent('.unsafe-dotEnV-casing')
106+
expect(code === '403' || code === '404').toBeTruthy()
101107
})
102108
} else {
103109
test('dummy test to make jest happy', async () => {

packages/playground/fs-serve/root/src/index.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ <h2>Nested Entry</h2>
4545

4646
<h2>Denied</h2>
4747
<pre class="unsafe-dotenv"></pre>
48+
<pre class="unsafe-dotEnV-casing"></pre>
4849

4950
<script type="module">
5051
import '../../entry'
@@ -202,14 +203,23 @@ <h2>Denied</h2>
202203
})
203204

204205
// .env, denied by default
205-
fetch('/@fs/' + ROOT + '/root/.env')
206+
fetch('/@fs/' + ROOT + '/root/src/.env')
206207
.then((r) => {
207208
text('.unsafe-dotenv', r.status)
208209
})
209210
.catch((e) => {
210211
console.error(e)
211212
})
212213

214+
// .env, for case insensitive file systems
215+
fetch('/@fs/' + ROOT + '/root/src/.EnV')
216+
.then((r) => {
217+
text('.unsafe-dotEnV-casing', r.status)
218+
})
219+
.catch((e) => {
220+
console.error(e)
221+
})
222+
213223
function text(sel, text) {
214224
document.querySelector(sel).textContent = text
215225
}

packages/vite/src/node/server/middlewares/static.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function serveRawFsMiddleware(
156156
}
157157
}
158158

159-
const _matchOptions = { matchBase: true }
159+
const _matchOptions = { matchBase: true, nocase: true }
160160

161161
export function isFileServingAllowed(
162162
url: string,

0 commit comments

Comments
 (0)