From e4df9e84768bf0a4709af62b7972a6671ad9c295 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 23 Oct 2024 14:00:59 +1300 Subject: [PATCH] fix(validator): :alien: validate id for uuid, not uuidv4 --- src/options/PropertySelects.ts | 2 +- src/options/options.ts | 2 +- src/options/validator.ts | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/options/PropertySelects.ts b/src/options/PropertySelects.ts index 4d55ec33..2b3317e5 100644 --- a/src/options/PropertySelects.ts +++ b/src/options/PropertySelects.ts @@ -83,7 +83,7 @@ export class SelectPropertyValueSelect extends PropertySelect { this.propertySelect.addEventListener('input', async () => { const databaseId = getDatabaseId(); - if (!typeGuards.isUUIDv4(databaseId)) return; + if (!typeGuards.isUUID(databaseId)) return; const accessToken = (await Storage.getNotionAuthorisation()).accessToken ?? await CONFIGURATION.FIELDS['notion.accessToken'].input.validate(true); diff --git a/src/options/options.ts b/src/options/options.ts index dcfb6627..66a00fcc 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -458,7 +458,7 @@ Object.values(buttons.restore).forEach(button => button.addEventListener('click' DatabaseSelect.element.addEventListener('input', async () => { const databaseId = DatabaseSelect.element.getValue(); - if (!typeGuards.isUUIDv4(databaseId)) return; + if (!typeGuards.isUUID(databaseId)) return; const accessToken = (await Storage.getNotionAuthorisation()).accessToken ?? await CONFIGURATION.FIELDS['notion.accessToken'].input.validate(true); diff --git a/src/options/validator.ts b/src/options/validator.ts index c310c3e4..e9a47e2c 100644 --- a/src/options/validator.ts +++ b/src/options/validator.ts @@ -296,13 +296,13 @@ export const typeGuards = { isTimeZoneRequest(value: unknown): value is string { return (typeof value === 'string' && (VALID_TIME_ZONES).includes(value)); }, - isUUIDv4(value: unknown): value is string { + isUUID(value: unknown): value is string { // allow hyphens to be optional as the Notion API doesn't require them // also, Notion URLs don't have them, so it wouldn't be very user friendly to require them - const hyphenatedRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i; - const nonHyphenatedRegex = /^[0-9A-F]{8}[0-9A-F]{4}4[0-9A-F]{3}[89AB][0-9A-F]{3}[0-9A-F]{12}$/i; + const hyphenatedRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i; + const nonHyphenatedRegex = /^[0-9A-F]{8}[0-9A-F]{4}[0-9A-F]{4}[89AB][0-9A-F]{3}[0-9A-F]{12}$/i; - return (typeof value === 'string') && [hyphenatedRegex, nonHyphenatedRegex].some(regex => regex.test(value.toUpperCase())); + return (typeof value === 'string') && [hyphenatedRegex, nonHyphenatedRegex].some(regex => regex.test(value)); }, }; @@ -370,7 +370,7 @@ export class RequiredNotionTokenField extends RequiredField { export class RequiredNotionDatabaseIdField extends RequiredField { public constructor(elementId: string) { - super(elementId, typeGuards.isUUIDv4, 'a valid database ID'); + super(elementId, typeGuards.isUUID, 'a valid database ID'); } protected override async validator(inputValue: NullIfEmpty): Promise | typeof InputFieldValidator.INVALID_INPUT> {