go-proto-validators icon indicating copy to clipboard operation
go-proto-validators copied to clipboard

UUID validator regex is incorrect

Open kostyay opened this issue 5 years ago • 0 comments

The validator fails for a completely valid UUID 96733dad-7258-716b-22cb-e7963b266675. Google parser parses it correctly, the generated validator does not.

The regex makes several incorrect assumptions, like hat the 3rd block must start with 4, which is not the case.

Code Sample:

package main

import (
	"fmt"
	"regexp"

	"github.com/google/uuid"
)

var _regex_GetApiTokenByClientIdRequest_ClientId = regexp.MustCompile(`^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[4][a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12})?$`)

func main() {


	guids := []string{"96733dad-7258-716b-22cb-e7963b266675", "89e20584-48b6-4b0b-9ce2-31e3d1125dad"}
	for _, g := range guids {
		_, err := uuid.Parse(g)
		fmt.Printf("v1: %s - %t\n", g, err == nil)
		a := _regex_GetApiTokenByClientIdRequest_ClientId.MatchString(g)
		fmt.Printf("v2: %s - %t\n", g, a)
	}
}

kostyay avatar Sep 09 '20 06:09 kostyay