Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #259 #266

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Next

- Bring back the [UMD](https://github.com/umdjs/umd) build (#261)
- Fix #259: Disallow trailing underscores in usernames in `webnative.lobby.isUsernameValid`.


### v0.26.0
Expand Down
4 changes: 4 additions & 0 deletions src/lobby/username.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ describe('isUsernameValid', () => {
expect(isUsernameValid("_startswith")).toBe(false)
})

it("does not allow suffixed underscores", () => {
expect(isUsernameValid("endswith_")).toBe(false)
})

it("does not allow spaces", () => {
expect(isUsernameValid("with space")).toBe(false)
})
Expand Down
1 change: 1 addition & 0 deletions src/lobby/username.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function isUsernameValid(username: string): boolean {
return !username.startsWith("-") &&
!username.endsWith("-") &&
!username.startsWith("_") &&
!username.endsWith("_") &&
/^[a-zA-Z0-9_-]+$/.test(username) &&
!USERNAME_BLOCKLIST.includes(username.toLowerCase())
}