fix(options): treat unit durations <= 0 as disabled in ParseURL#3866
Merged
Conversation
ParseURL documents that a duration query parameter is disabled with a value <= 0, but queryOptions.duration() applied that rule only to plain integers. A duration written with a unit went through time.ParseDuration and was returned as-is, so 0s did not disable the field: read_timeout=0s fell through to the default instead of disabling like read_timeout=0. Apply the same <= 0 check in the ParseDuration branch, matching the plain-integer form, and cover it with two TestParseURL cases (conn_max_idle_time=0s and =-1s).
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ParseURLdocuments that a duration query parameter is disabled with a value<= 0:That only works for plain integers.
queryOptions.duration()returns the-1disable sentinel in the integer branch, but a duration written with a unit goes throughtime.ParseDurationand is returned as-is, so a zero value with a unit is not disabled and falls through to the default:(
ReadTimeoutvalues are shown afterinit(), which maps the-1sentinel to the runtime no-timeout value.)The fix applies the same
<= 0check in theParseDurationbranch so0sdisables the field like0already does. Negative values with a unit (-1s) are normalized to the same-1sentinel for consistency; those already disabled at runtime sincedeadline()treats anytimeout <= 0as no deadline, so that part is parse-level consistency rather than a behavior change.Added two
conn_max_idle_timecases (0s,-1s) toTestParseURL; both fail before the change and pass after.go vet ./...,gofmt, andgo build ./...are clean. The server-backed suite needs Docker so I did not run it, but the change is confined to URL parsing and is covered byTestParseURL.Note
Low Risk
Small, localized change to URL option parsing with new unit tests; no auth or connection logic changes beyond correct timeout disable semantics.
Overview
ParseURLduration query params now treat values with units the same as plain integers when disabling timeouts: aftertime.ParseDuration,dur <= 0returns the-1sentinel instead of passing through0(whichOptions.init()would turn into library defaults).This closes a doc/behavior gap where
conn_max_idle_time=0disabled idle timeout butconn_max_idle_time=0sdid not. The same logic applies to other duration URL fields (read_timeout,dial_timeout, etc.).Tests:
TestParseURLaddsconn_max_idle_time=0sandconn_max_idle_time=-1sexpectingConnMaxIdleTime: -1.Reviewed by Cursor Bugbot for commit 5b43405. Bugbot is set up for automated code reviews on this repo. Configure here.