validation: anchor duration regex to reject invalid tokens#619
validation: anchor duration regex to reject invalid tokens#619bernot-dev wants to merge 1 commit into
Conversation
I anchored the duration validation regex to ensure the entire string is validated. Previously, the durationMatcher regex was unanchored. This allowed ParseDuration to match valid duration substrings embedded within invalid strings, ignoring the invalid text. For example, "1s invalid" would successfully validate and return a duration of 1s. To fix this, I introduced a two-step validation: 1. Check the candidate string against durationValidator, an anchored regex that ensures the input consists only of valid duration components. 2. Sum the components using durationMatcher. This allows composite durations like "1w2s" or "1w 2d 3h 4m" to be parsed while rejecting inputs with invalid tokens. I added positive and negative test cases to cover expected behavior.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: bernot-dev The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @bernot-dev! |
|
Closing this in favor of #621, which is a much more direct backport of the upstream go-openapi library. |
I anchored the duration validation regex to ensure the entire string is validated.
Previously, the durationMatcher regex was unanchored. This allowed ParseDuration to match valid duration substrings embedded within invalid strings, ignoring the invalid text. For example, "1s invalid" would successfully validate and return a duration of 1s.
To fix this, I introduced a two-step validation:
This allows composite durations like "1w2s" or "1w 2d 3h 4m" to be parsed while rejecting inputs with invalid tokens. I added positive and negative test cases to cover expected behavior.