Unverified Commit 40e178e6 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure rewrite does not override params from page in minimal mode (#25074)

This makes sure a catch-all rewrite doesn't override the params from a dynamic route in minimal mode, it also makes sure we don't attempt applying headers and rewrites un-necessarily in minimal mode. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
parent eaf74c1c
...@@ -289,7 +289,13 @@ export function getUtils({ ...@@ -289,7 +289,13 @@ export function getUtils({
// on the parsed params, this is used to signal if we need // on the parsed params, this is used to signal if we need
// to parse x-now-route-matches or not // to parse x-now-route-matches or not
const isDefaultValue = Array.isArray(value) const isDefaultValue = Array.isArray(value)
? value.every((val, idx) => val === defaultRouteMatches![key][idx]) ? value.some((val) => {
const defaultValue = defaultRouteMatches![key]
return Array.isArray(defaultValue)
? defaultValue.includes(val)
: defaultValue === val
})
: value === defaultRouteMatches![key] : value === defaultRouteMatches![key]
if (isDefaultValue || typeof value === 'undefined') { if (isDefaultValue || typeof value === 'undefined') {
......
...@@ -818,7 +818,9 @@ export default class Server { ...@@ -818,7 +818,9 @@ export default class Server {
} }
// Headers come very first // Headers come very first
const headers = this.customRoutes.headers.map((r) => { const headers = this.minimalMode
? []
: this.customRoutes.headers.map((r) => {
const headerRoute = getCustomRoute(r, 'header') const headerRoute = getCustomRoute(r, 'header')
return { return {
match: headerRoute.match, match: headerRoute.match,
...@@ -971,6 +973,7 @@ export default class Server { ...@@ -971,6 +973,7 @@ export default class Server {
let afterFiles: Route[] = [] let afterFiles: Route[] = []
let fallback: Route[] = [] let fallback: Route[] = []
if (!this.minimalMode) {
if (Array.isArray(this.customRoutes.rewrites)) { if (Array.isArray(this.customRoutes.rewrites)) {
afterFiles = this.customRoutes.rewrites.map(buildRewrite) afterFiles = this.customRoutes.rewrites.map(buildRewrite)
} else { } else {
...@@ -978,6 +981,7 @@ export default class Server { ...@@ -978,6 +981,7 @@ export default class Server {
afterFiles = this.customRoutes.rewrites.afterFiles.map(buildRewrite) afterFiles = this.customRoutes.rewrites.afterFiles.map(buildRewrite)
fallback = this.customRoutes.rewrites.fallback.map(buildRewrite) fallback = this.customRoutes.rewrites.fallback.map(buildRewrite)
} }
}
const catchAllRoute: Route = { const catchAllRoute: Route = {
match: route('/:path*'), match: route('/:path*'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment