Skip to content

Commit 1ba50d7

Browse files
committed
Make the RoomIdPattern strict
1 parent ec459c8 commit 1ba50d7

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

server/common/const.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ const (
66
HostStatusClosing = 2
77

88
RoomIdLen = 32
9-
RoomIdPattern = "^[0-9a-f]+$"
9+
RoomIdPattern = "^[0-9a-f]{32}$"
1010
)

server/game/repository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func RandomHex(n int) string {
8484
}
8585

8686
func IsValidRoomId(id string) bool {
87-
return rerid.Match([]byte(id))
87+
return rerid.MatchString(id)
8888
}
8989

9090
type Repository struct {

server/game/repository_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ func TestQueries(t *testing.T) {
4040

4141
func TestIsValidRoomId(t *testing.T) {
4242
tests := map[string]bool{
43-
"123456789abcdef": true,
44-
"123456789ABCDEF": false,
45-
"": false,
43+
"0123456789abcdef0123456789abcdef": true,
44+
"0123456789ABCDEF0123456789ABCDEF": false,
45+
"0123456789abcdef0123456789abcde": false,
46+
"0123456789abcdef0123456789abcdef0": false,
47+
"": false,
4648
}
4749

4850
for id, valid := range tests {

0 commit comments

Comments
 (0)