Skip to content

Commit

Permalink
Make the RoomIdPattern strict
Browse files Browse the repository at this point in the history
  • Loading branch information
makiuchi-d committed Apr 3, 2024
1 parent ec459c8 commit 1ba50d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ const (
HostStatusClosing = 2

RoomIdLen = 32
RoomIdPattern = "^[0-9a-f]+$"
RoomIdPattern = "^[0-9a-f]{32}$"
)
2 changes: 1 addition & 1 deletion server/game/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func RandomHex(n int) string {
}

func IsValidRoomId(id string) bool {
return rerid.Match([]byte(id))
return rerid.MatchString(id)
}

type Repository struct {
Expand Down
8 changes: 5 additions & 3 deletions server/game/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func TestQueries(t *testing.T) {

func TestIsValidRoomId(t *testing.T) {
tests := map[string]bool{
"123456789abcdef": true,
"123456789ABCDEF": false,
"": false,
"0123456789abcdef0123456789abcdef": true,
"0123456789ABCDEF0123456789ABCDEF": false,
"0123456789abcdef0123456789abcde": false,
"0123456789abcdef0123456789abcdef0": false,
"": false,
}

for id, valid := range tests {
Expand Down

0 comments on commit 1ba50d7

Please sign in to comment.