rewriteTag attempts to match the original token against the email and telephone number. The tag is expected to be in lowercase. On success, it returns a slice with the original tag and the tag with the corresponding prefix. It returns an empty slice if the tag is invalid. TODO: consider inferring co
(orig, countryCode string)
| 375 | // empty slice if the tag is invalid. |
| 376 | // TODO: consider inferring country code from user location. |
| 377 | func rewriteTag(orig, countryCode string) []string { |
| 378 | // Check if the tag already has a prefix e.g. basic:alice. |
| 379 | if prefixedTagRegexp.MatchString(orig) { |
| 380 | return []string{orig} |
| 381 | } |
| 382 | |
| 383 | // Check if token can be rewritten by any of the validators |
| 384 | param := map[string]any{"countryCode": countryCode} |
| 385 | for name, conf := range globals.validators { |
| 386 | if conf.addToTags { |
| 387 | val := store.Store.GetValidator(name) |
| 388 | if tag, _ := val.PreCheck(orig, param); tag != "" { |
| 389 | return []string{orig, tag} |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if tagRegexp.MatchString(orig) { |
| 395 | return []string{orig} |
| 396 | } |
| 397 | |
| 398 | // invalid generic tag |
| 399 | |
| 400 | return nil |
| 401 | } |
| 402 | |
| 403 | // rewriteTagSlice calls rewriteTag for each slice member and return a new slice with original and converted values. |
| 404 | func rewriteTagSlice(tags []string, countryCode string) []string { |
no test coverage detected
searching dependent graphs…