-
-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure we check names using the full UTF-8 character set.
- Loading branch information
Showing
2 changed files
with
16 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { CharacteristicValue, Nullable } from "../../types"; | ||
|
||
/** | ||
* Checks that supplied field meets Apple HomeKit naming rules | ||
* https://developer.apple.com/design/human-interface-guidelines/homekit#Help-people-choose-useful-names | ||
* @private Private API | ||
*/ | ||
|
||
// 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 { | ||
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 | ||
export function checkName(displayName: string, name: string, value: Nullable<CharacteristicValue>): void { | ||
|
||
if (!validHK.test(value) || !startWith.test(value) || !endWith.test(value)) { | ||
// Ensure the string starts and ends with a Unicode letter or number and allow any combination of letters, numbers, spaces, and apostrophes in the middle. | ||
if (typeof value === "string" && value.length && !(new RegExp(/^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u)).test(value)) { | ||
console.warn("HAP-NodeJS WARNING: The accessory '" + displayName + "' is getting published with the characteristic '" + | ||
name + "'" + " not following HomeKit naming rules ('" + value + "'). " + | ||
"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!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters