peers/peerjs

Seemingly valid peer ids rejected by validateId function

Open

#849 opened on May 19, 2021

View on GitHub
 (1 comment) (2 reactions) (0 assignees)TypeScript (11,580 stars) (1,406 forks)batch import
bugclientconfirmedhelp wanted

Description

The API documentation states: The ID must start and end with an alphanumeric character (lower or upper case character or a digit). In the middle of the ID spaces, dashes (-) and underscores (_) are allowed.

Problem: According to the documentation the below ids should be valid but instead throw the error "invalid-id". The docs fail to mention that spaces, dashes, and underscores cannot be next to each other. acb123_-xyz acb123__xyz acb123--xyz acb123 -xyz

Solution: If there is no functional reason for this limitation the validateId function regex could be updated to reflect the documentation. Alternatively the documentation could be amended.

The regex that validate the peer id is currently: ^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$

Updated regex to match documentation: ^[A-Za-z0-9][A-Za-z0-9_- ]*[A-Za-z0-9]$

Contributor guide