[ 
https://issues.apache.org/jira/browse/THRIFT-6012?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Roman Dmytrenko updated THRIFT-6012:
------------------------------------
    Description: 
The Go struct validator generator has two bugs in vt.pattern handling:

1. Incorrect argument order - regexp.MatchString(target, pattern) swaps the 
parameters. The correct signature is regexp.MatchString(pattern, s), so the 
pattern must come first. This causes all vt.pattern validations to behave 
incorrectly (matching the pattern against the pattern string rather than 
against the field value).
2. Repeated regex compilation - regexp.MatchString compiles the pattern on 
every call. For structs validated frequently (e.g., in a hot loop), this is 
wasteful.

  was:
The Go struct validator generator has two bugs in vt.pattern handling:


1. Incorrect argument order - `regexp.MatchString(target, pattern)` swaps the 
parameters. The correct signature is regexp.MatchString(pattern, s), so the 
pattern must come first. This causes all vt.pattern validations to behave 
incorrectly (matching the pattern against the pattern string rather than 
against the field value).
2. Repeated regex compilation - regexp.MatchString compiles the pattern on 
every call. For structs validated frequently (e.g., in a hot loop), this is 
wasteful.


> Fix inverted regexp.MatchString arguments and precompile patterns in Go 
> validator
> ---------------------------------------------------------------------------------
>
>                 Key: THRIFT-6012
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6012
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>            Reporter: Roman Dmytrenko
>            Priority: Major
>
> The Go struct validator generator has two bugs in vt.pattern handling:
> 1. Incorrect argument order - regexp.MatchString(target, pattern) swaps the 
> parameters. The correct signature is regexp.MatchString(pattern, s), so the 
> pattern must come first. This causes all vt.pattern validations to behave 
> incorrectly (matching the pattern against the pattern string rather than 
> against the field value).
> 2. Repeated regex compilation - regexp.MatchString compiles the pattern on 
> every call. For structs validated frequently (e.g., in a hot loop), this is 
> wasteful.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to