HAP-NodeJS icon indicating copy to clipboard operation
HAP-NodeJS copied to clipboard

Special Characters in Name

Open NorthernMan54 opened this issue 1 year ago • 6 comments

Analysis

@Supereg With the recent IOS versions I have noticed that accessory names are now being checked for special characters or emoji, and am thinking that we should add an error or warning message when these are being used. I was using ( and ), but there are likely others. I did find that - did not trigger the message

IMG_1381 IMG_1380

Am wondering if this is a potential trigger of this issue - https://github.com/homebridge/homebridge/issues/3373#issuecomment-1558438317

Expected Behavior

An error or warning message to be logged when a accessory name contains an unsupported character.

Steps To Reproduce

Create an accessory with invalid character

Logs

None

Configuration

not needed

Environment

  • OS:
  • Software:
  • Node:
  • npm:

Process Supervisor

hb-service

Additional Context

No response

NorthernMan54 avatar Jun 27 '23 00:06 NorthernMan54

This has always been the case and have code to validate names on my stuff

https://developer.apple.com/design/human-interface-guidelines/homekit

Use only alphanumeric, space, and apostrophe characters. Start and end with an alphabetic or numeric character. Don’t include emojis.

I have a function like this

    function validateHomeKitName(nameToMakeValid) {
        // Strip invalid characters to meet HomeKit naming requirements
        // Ensure only letters or numbers are at the beginning AND/OR end of string
        return nameToMakeValid.replace(/[^A-Za-z0-9 ,.-]/g, "").replace(/^[^a-zA-Z0-9]*/g, "").replace(/[^a-zA-Z0-9]+$/g, "");
    }

n0rt0nthec4t avatar Jun 27 '23 05:06 n0rt0nthec4t

HomeKit also chokes on a Manufacturer Name with a /.

ebaauw avatar Jun 27 '23 05:06 ebaauw

We might extend the sanity checks we already have in Accessory.validateAccessory. There we check for empty values for those Characteristics.

I'm not sure if it makes sense to automatically alter names(?). We could offer some help if they attempt it in Homebridge UI, but we can't really prevent it, if they configure accessory names via the config themselves.

Supereg avatar Jun 27 '23 12:06 Supereg

@Supereg Am thinking your recommendation to extend Accessory.validateAccessory with the check creating a log entry makes the most sense. Something similar to the existing checks.

Give me a few days, and I will submit a pull request.

NorthernMan54 avatar Jun 27 '23 13:06 NorthernMan54

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 28 '23 11:07 github-actions[bot]

Not stale

NorthernMan54 avatar Jul 28 '23 11:07 NorthernMan54

I wonder if the current implementation is too restrictive, as dash or punctuation are a) not uncommon and b) supported by HomeKit.

Rolling out this change as is may result in a lot of confusion (and many people goint to rework their setup, even if it is not needed).

muenzpraeger avatar Aug 12 '24 08:08 muenzpraeger

@muenzpraeger see above https://github.com/homebridge/HAP-NodeJS/issues/1008#issuecomment-1608825576

NorthernMan54 avatar Aug 12 '24 11:08 NorthernMan54

I'm aware of the HIG reference. Now, I've at least 40 different accessories that have a special character (. or -) in their name, and now I'm being spammed on startup.

I'd say it's ok for doing a validation check when a new accessory is created. Not for existing devices. Alternatively the option should be available to disable this warning.

muenzpraeger avatar Aug 12 '24 13:08 muenzpraeger

@muenzpraeger What happens when you edit the name in the Home app ? I found that I couldn't save the edited name, hence us adding the warning.

NorthernMan54 avatar Aug 12 '24 14:08 NorthernMan54

Works for me (at least with . and -. Video is low-res b/c of GitHub file limits.

https://github.com/user-attachments/assets/e7a87d1c-4497-485d-a497-dbbf9d7d95b7

muenzpraeger avatar Aug 12 '24 14:08 muenzpraeger