Skip to content

Conversation

Jefftree
Copy link
Member

Fixes #523.

Patch was applied from go-openapi/strfmt. go-openapi/strfmt#144

/assign @jpbetz

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 13, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Jefftree
Once this PR has been reviewed and has the lgtm label, please assign sttts for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 13, 2025
@liggitt
Copy link
Member

liggitt commented Aug 14, 2025

Fixes #523.

does this actually fix all the issues raised in 523? that looks like it had a lot of other things mixed in, like decimal support, long-unit support, etc

}

durationMatcher = regexp.MustCompile(`((\d+)\s*([A-Za-zµ]+))`)
durationMatcher = regexp.MustCompile(`(((?:-\s?)?\d+)\s*([A-Za-zµ]+))`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you clarify what additional values this allows? it's not clear to me that accepting new internal whitespaces between - and the number is a good idea here

@Jefftree
Copy link
Member Author

Fixes #523.

does this actually fix all the issues raised in 523? that looks like it had a lot of other things mixed in, like decimal support, long-unit support, etc

Ah thanks for the catch, it does not. The primary concern was around decimal & long-unit support which is not addressed, so I don't see much value in getting just the negative duration part in.

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2025
durationMatcher = regexp.MustCompile(`(((?:-\s?)?\d+)\s*([A-Za-zµ]+))`)
)

// IsDuration returns true if the provided string is a valid duration
Copy link
Member

@liggitt liggitt Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParseDuration uses durationMatcher.FindAllStringSubmatch with an unpinned regex, which will skip and ignore any random junk before / between / after matches of the regex.

See https://go.dev/play/p/fCur5WS4zK5 for the type of nonsense IsDuration would accept currently.

To actually address the problem of decimal junk being accepted but ignored, we need the regex to fully define what we allow, and be pinned to the beginning / end of the string. Something like this

singleDurationMatcher = `-?(\d+)\s*([A-Za-zµ]+)`
// I'm not sure what separators we *intend* to allow between the items, whitespace? comma? something else?
multiDuration = `^(`+singleDurationMatcher+`)(\s*`+singleDurationMatcher+`)*$`
durationMatcher = regexp.MustCompile(multiDuration)
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected results from the duration format

4 participants