@@ -248,9 +248,7 @@ func (sv *LobbyService) handleCreateRoom(w http.ResponseWriter, r *http.Request)
248
248
}
249
249
250
250
var (
251
- idRegexp = regexp .MustCompile ("^[0-9a-f]+$" )
252
- numRegexp = regexp .MustCompile ("^[0-9]+$" )
253
- grpRegexp = regexp .MustCompile ("^[0-9]+$" )
251
+ idRegexp = regexp .MustCompile ("^[0-9a-f]+$" )
254
252
)
255
253
256
254
type JoinVars struct {
@@ -263,25 +261,19 @@ func NewJoinVars(r *http.Request) JoinVars {
263
261
264
262
func (vars JoinVars ) roomId () (string , bool ) {
265
263
id := vars .r .PathValue ("roomId" )
266
- return id , idRegexp .Match ([] byte ( id ) )
264
+ return id , idRegexp .MatchString ( id )
267
265
}
268
266
269
267
func (vars JoinVars ) roomNumber () (int32 , bool ) {
270
268
v := vars .r .PathValue ("roomNumber" )
271
- if ! numRegexp .Match ([]byte (v )) {
272
- return 0 , false
273
- }
274
269
n , err := strconv .ParseInt (v , 10 , 32 )
275
- return int32 (n ), err == nil && n != 0
270
+ return int32 (n ), err == nil && n > 0
276
271
}
277
272
278
273
func (vars JoinVars ) searchGroup () (uint32 , bool ) {
279
274
v := vars .r .PathValue ("searchGroup" )
280
- if ! grpRegexp .Match ([]byte (v )) {
281
- return 0 , false
282
- }
283
275
n , err := strconv .ParseInt (v , 10 , 32 )
284
- return uint32 (n ), err == nil
276
+ return uint32 (n ), err == nil && n >= 0
285
277
}
286
278
287
279
func (sv * LobbyService ) handleJoinRoom (w http.ResponseWriter , r * http.Request ) {
0 commit comments