Skip to content

Commit 610741e

Browse files
refactor: log dropped invalid route entries during normalization
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 3991e6b commit 610741e

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/views/Validation.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,28 @@ function isRecord(value: unknown): value is Record<string, unknown> {
204204
return typeof value === 'object' && value !== null
205205
}
206206
207-
function toStringRecord(value: unknown): Record<string, string> {
207+
function normalizeRouteRecord(value: unknown, source: 'params' | 'query'): Record<string, string> {
208208
if (!isRecord(value)) {
209209
return {}
210210
}
211211
212212
const result: Record<string, string> = {}
213+
const droppedKeys: string[] = []
213214
for (const [key, entry] of Object.entries(value)) {
214215
if (typeof entry === 'string') {
215216
result[key] = entry
217+
} else {
218+
droppedKeys.push(key)
216219
}
217220
}
218221
222+
if (droppedKeys.length > 0) {
223+
logger.warn('Validation route normalization dropped non-string entries', {
224+
source,
225+
droppedKeys,
226+
})
227+
}
228+
219229
return result
220230
}
221231
@@ -429,8 +439,8 @@ const route = computed<RouteState>(() => {
429439
const rawRoute = (instance?.proxy?.$route as Partial<RouteState> | undefined) ?? {}
430440
return {
431441
name: typeof rawRoute.name === 'string' ? rawRoute.name : null,
432-
params: toStringRecord(rawRoute.params),
433-
query: toStringRecord(rawRoute.query),
442+
params: normalizeRouteRecord(rawRoute.params, 'params'),
443+
query: normalizeRouteRecord(rawRoute.query, 'query'),
434444
}
435445
})
436446
const router = computed<RouterState>(() => (instance?.proxy?.$router as RouterState | undefined) ?? { push: () => {}, replace: () => {} })

0 commit comments

Comments
 (0)