Skip to content

Commit

Permalink
added the pattern that is failing
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Jun 28, 2024
1 parent 6dd97b4 commit 69dfb2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/lib/Characteristic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 5 additions & 7 deletions src/lib/util/checkName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down

0 comments on commit 69dfb2d

Please sign in to comment.