Skip to content

Commit 07e39cd

Browse files
committed
fix(nuxt): match route rules case-insensitively to mirror vue-router
Refs: GHSA-mm7m-92g8-7m47
1 parent 4b054e9 commit 07e39cd

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/nitro-server/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ export async function bundle (nuxt: Nuxt & { _nitro?: Nitro }): Promise<void> {
432432
return cachedMatchers[key] = `
433433
import { defu } from 'defu'
434434
const matcher = ${matcher}
435-
export default (path) => defu({}, ...matcher('', path).map(r => r.data).reverse())
435+
export default (path) => defu({}, ...matcher('', typeof path === 'string' ? path.toLowerCase() : path).map(r => r.data).reverse())
436436
`
437437
},
438438
})

packages/nuxt/src/app/composables/manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function getRouteRules (url: string): Record<string, any>
6868
export function getRouteRules (arg: string | H3Event | { path: string }) {
6969
const path = typeof arg === 'string' ? arg : arg.path
7070
try {
71-
return routeRulesMatcher(path)
71+
return routeRulesMatcher(path.toLowerCase())
7272
} catch (e) {
7373
console.error('[nuxt] Error matching route rules.', e)
7474
return {}

test/nuxt/composables.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,15 @@ describe.skipIf(!isTestingAppManifest)('app manifests', () => {
536536
}
537537
`)
538538
})
539+
it('matches case-insensitively to mirror vue-router defaults', () => {
540+
expect(getRouteRules({ path: '/Pre/spa/thing' })).toMatchObject({
541+
prerender: true,
542+
ssr: false,
543+
})
544+
expect(getRouteRules({ path: '/PRE/test' })).toMatchObject({
545+
redirect: '/',
546+
})
547+
})
539548
})
540549

541550
describe('compiled route rules', () => {

0 commit comments

Comments
 (0)