From 7716c57811d360118cfab08c6125aada9010b3a5 Mon Sep 17 00:00:00 2001 From: aikrom Date: Wed, 9 Feb 2022 15:02:54 +0700 Subject: [PATCH 1/2] fix: support UUIDs as per RFC spec (#50) --- adonis-typings/route.ts | 2 +- src/Router/Matchers.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/adonis-typings/route.ts b/adonis-typings/route.ts index 9cdbe1a1..7e1039b7 100644 --- a/adonis-typings/route.ts +++ b/adonis-typings/route.ts @@ -565,7 +565,7 @@ declare module '@ioc:Adonis/Core/Route' { /** * Enforce value to be formatted as uuid */ - uuid(): { match: RegExp } + uuid(): { match: RegExp; cast: (value: string) => string } /** * Enforce value to be formatted as slug diff --git a/src/Router/Matchers.ts b/src/Router/Matchers.ts index a3425f48..fe8d2a96 100644 --- a/src/Router/Matchers.ts +++ b/src/Router/Matchers.ts @@ -30,8 +30,11 @@ export class RouteMatchers extends Macroable implements RouteMatchersContract { /** * Enforce value to be formatted as uuid */ - public uuid(): { match: RegExp } { - return { match: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/ } + public uuid(): { match: RegExp; cast: (value: string) => string } { + return { + match: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/, + cast: (value) => value.toLowerCase(), + } } /** From 064d16b4337a9ccf7f66e4dd28b952026d07e649 Mon Sep 17 00:00:00 2001 From: aikrom Date: Wed, 23 Feb 2022 10:07:47 +0700 Subject: [PATCH 2/2] fixed uuid match regex to check case insensitively --- src/Router/Matchers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Router/Matchers.ts b/src/Router/Matchers.ts index fe8d2a96..26064d77 100644 --- a/src/Router/Matchers.ts +++ b/src/Router/Matchers.ts @@ -32,7 +32,7 @@ export class RouteMatchers extends Macroable implements RouteMatchersContract { */ public uuid(): { match: RegExp; cast: (value: string) => string } { return { - match: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/, + match: /^[0-9a-zA-F]{8}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{12}$/, cast: (value) => value.toLowerCase(), } }