From 69dfb2d6b6ce853ba8c0e566717fc8e29bc9c0f1 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Fri, 28 Jun 2024 06:40:28 -0500 Subject: [PATCH] added the pattern that is failing --- src/lib/Characteristic.ts | 2 +- src/lib/util/checkName.ts | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib/Characteristic.ts b/src/lib/Characteristic.ts index 6457cacd5..4a65147f1 100644 --- a/src/lib/Characteristic.ts +++ b/src/lib/Characteristic.ts @@ -2977,7 +2977,7 @@ export class Characteristic extends EventEmitter { value = value.substring(0, maxLength); } - if (this.UUID === "000000E3-0000-1000-8000-0026BB765291") { + if (this.UUID === Characteristic.ConfiguredName.UUID) { checkName(this.displayName, "ConfiguredName", value); } diff --git a/src/lib/util/checkName.ts b/src/lib/util/checkName.ts index b53a98e24..26a3d0898 100644 --- a/src/lib/util/checkName.ts +++ b/src/lib/util/checkName.ts @@ -6,18 +6,16 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types export function checkName(displayName: string, name: string, value: any): void { - if (!value) { - console.warn(`HAP-NodeJS WARNING: The accessory '${displayName}' is getting published with an empty '${name}'. This is not allowed.`); - return; - } - - const validHK = /^[a-zA-Z0-9\s'-.]+$/; // Ensure only letter, numbers, apostrophe, or dash + const validHK = /^[a-zA-Z0-9\s'-.]+$/; // Ensure only letter, numbers, apostrophe, or dash const startWith = /^[a-zA-Z0-9]/; // Ensure only letters or numbers are at the beginning of string const endWith = /[a-zA-Z0-9]$/; // Ensure only letters or numbers are at the end of string + const pattern = !validHK.test(value) ? "doesn't have only letter, numbers, apostrophe, or dash" + : !startWith.test(value) ? "doesn't start with letter or number," + : !endWith.test(value) ? "doesn't end with letter or number," : ""; if (!validHK.test(value) || !startWith.test(value) || !endWith.test(value)) { console.warn("HAP-NodeJS WARNING: The accessory '" + displayName + "' is getting published with the characteristic '" + - name + "'" + " not following HomeKit naming rules ('" + value + "'). " + + name + "'" + " not following HomeKit naming rules ('" + value + "', " + " with a pattern that'" + pattern + "'." + "Use only alphanumeric, space, and apostrophe characters, start and end with an alphabetic or numeric character, and don't include emojis. " + "This might prevent the accessory from being added to the Home App or leading to the accessory being unresponsive!"); }