Skip to content

Commit

Permalink
fix: port #15653 to v2 (#15657)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jan 19, 2024
1 parent ea814d7 commit 1f855dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/playground/fs-serve/__tests__/fs-serve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ describe('main', () => {
})

test('denied', async () => {
expect(await page.textContent('.unsafe-dotenv')).toBe('404')
expect(await page.textContent('.unsafe-dotenv')).toBe('403')
})

test('denied EnV casing', async () => {
// It is 403 in case insensitive system, 404 in others
const code = await page.textContent('.unsafe-dotEnV-casing')
expect(code === '403' || code === '404').toBeTruthy()
})
} else {
test('dummy test to make jest happy', async () => {
Expand Down
12 changes: 11 additions & 1 deletion packages/playground/fs-serve/root/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h2>Nested Entry</h2>

<h2>Denied</h2>
<pre class="unsafe-dotenv"></pre>
<pre class="unsafe-dotEnV-casing"></pre>

<script type="module">
import '../../entry'
Expand Down Expand Up @@ -202,14 +203,23 @@ <h2>Denied</h2>
})

// .env, denied by default
fetch('/@fs/' + ROOT + '/root/.env')
fetch('/@fs/' + ROOT + '/root/src/.env')
.then((r) => {
text('.unsafe-dotenv', r.status)
})
.catch((e) => {
console.error(e)
})

// .env, for case insensitive file systems
fetch('/@fs/' + ROOT + '/root/src/.EnV')
.then((r) => {
text('.unsafe-dotEnV-casing', r.status)
})
.catch((e) => {
console.error(e)
})

function text(sel, text) {
document.querySelector(sel).textContent = text
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function serveRawFsMiddleware(
}
}

const _matchOptions = { matchBase: true }
const _matchOptions = { matchBase: true, nocase: true }

export function isFileServingAllowed(
url: string,
Expand Down

0 comments on commit 1f855dc

Please sign in to comment.