From 8b7d3f0e20ba3c973ebe58ea3d79dd9ff3f46b89 Mon Sep 17 00:00:00 2001 From: titivuk Date: Mon, 1 Nov 2021 18:23:53 +0100 Subject: [PATCH] fix(common): ParseUUIDPipe - make uuid regexp dictionary protected static property --- packages/common/pipes/parse-uuid.pipe.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/common/pipes/parse-uuid.pipe.ts b/packages/common/pipes/parse-uuid.pipe.ts index ae35eb70de0..850d26f435b 100644 --- a/packages/common/pipes/parse-uuid.pipe.ts +++ b/packages/common/pipes/parse-uuid.pipe.ts @@ -10,13 +10,6 @@ import { HttpErrorByCode, } from '../utils/http-error-by-code.util'; -const uuid = { - 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, - 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, - 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, - all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i, -}; - export interface ParseUUIDPipeOptions { version?: '3' | '4' | '5'; errorHttpStatusCode?: ErrorHttpStatusCode; @@ -25,6 +18,12 @@ export interface ParseUUIDPipeOptions { @Injectable() export class ParseUUIDPipe implements PipeTransform { + protected static uuidRegExps = { + 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, + 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i, + }; private readonly version: '3' | '4' | '5'; protected exceptionFactory: (errors: string) => any; @@ -57,7 +56,7 @@ export class ParseUUIDPipe implements PipeTransform { if (typeof str !== 'string') { throw this.exceptionFactory('The value passed as UUID is not a string'); } - const pattern = uuid[version]; + const pattern = ParseUUIDPipe.uuidRegExps[version]; return pattern && pattern.test(str); } }