@@ -20,6 +20,7 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"reflect"
23
+ "regexp"
23
24
"strings"
24
25
"unicode"
25
26
)
@@ -327,11 +328,27 @@ type tag struct {
327
328
Param string // parameter to send to the validation function
328
329
}
329
330
331
+ // separate by no escaped commas
332
+ var sepPattern * regexp.Regexp = regexp .MustCompile (`((?:^|[^\\])(?:\\\\)*),` )
333
+
334
+ func splitUnescapedComma (str string ) []string {
335
+ ret := []string {}
336
+ indexes := sepPattern .FindAllStringIndex (str , - 1 )
337
+ last := 0
338
+ for _ , is := range indexes {
339
+ ret = append (ret , str [last :is [1 ]- 1 ])
340
+ last = is [1 ]
341
+ }
342
+ ret = append (ret , str [last :])
343
+ return ret
344
+ }
345
+
330
346
// parseTags parses all individual tags found within a struct tag.
331
347
func (mv * Validator ) parseTags (t string ) ([]tag , error ) {
332
- tl := strings . Split ( t , "," )
348
+ tl := splitUnescapedComma ( t )
333
349
tags := make ([]tag , 0 , len (tl ))
334
350
for _ , i := range tl {
351
+ i = strings .Replace (i , `\,` , "," , - 1 )
335
352
tg := tag {}
336
353
v := strings .SplitN (i , "=" , 2 )
337
354
tg .Name = strings .Trim (v [0 ], " " )
0 commit comments