Skip to content

fix: validate "uri" format for absolute URIs with a fragment (#131)#269

Merged
fredbi merged 1 commit into
go-openapi:masterfrom
patchwright:fix/uri-format-fragment
Jun 22, 2026
Merged

fix: validate "uri" format for absolute URIs with a fragment (#131)#269
fredbi merged 1 commit into
go-openapi:masterfrom
patchwright:fix/uri-format-fragment

Conversation

@patchwright

Copy link
Copy Markdown
Contributor

Problem

Fixes #131. The "uri" format rejects absolute URIs that carry a fragment with an empty path, e.g. https://portal.azure.com#@930d042f-..., reporting them as must be of type uri. These are valid per RFC 3986. Confirmed on master HEAD 00af19e.

Root cause

isRequestURI validates with url.ParseRequestURI, which is documented to assume the input carries no #fragment (RFC 3986 §3.5). With no path separating host and fragment, host#@frag is parsed as userinfo (host# before the @) and rejected as net/url: invalid userinfo.

Fix

Strip the fragment before calling url.ParseRequestURI, matching how url.Parse handles RFC 3986. This preserves the existing absolute-URI check (scheme still required, relative paths still rejected) and changes only the fragment case. 8 lines in default.go; no API changes.

How to test

$ go test -run '^TestFormatURI$' .
ok      github.com/go-openapi/strfmt    0.010s

On unpatched master the new sample fails:

--- FAIL: TestFormatURI (0.00s)
    default_test.go:27: expected "https://portal.azure.com#@930d042f-8145-fragment" of type uri to be valid

Backward compatibility

No breaking changes. The fix only newly accepts URIs that are valid per RFC 3986; inputs outside the fragment-with-empty-path case keep their previous accept/reject result.


Assisted-by: Claude (code generation, reviewed and tested locally)

@patchwright patchwright force-pushed the fix/uri-format-fragment branch from f957547 to 3506a4d Compare June 20, 2026 08:55
@fredbi

fredbi commented Jun 20, 2026

Copy link
Copy Markdown
Member

Thanks for posting this. i’ll review over the weekend.

@fredbi fredbi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've updated the linter config so goconst won't annoy us any longer. Please rebase.

I am okay with the change, although this story about URIs is far from over (now we let pass invalid URIs that have illegal fragments, before we did not accept empty fragments). I am accepting this change as a temporary solution that closes a very narrow issue, not as a silver bullet fix (so this is "patch almost wright"...

Thanks for your contribution. This helps us move forward.

Cheers

Comment thread default.go
Comment thread default_test.go
…api#131)

Signed-off-by: patchwright <patchwright@users.noreply.github.com>
@fredbi fredbi force-pushed the fix/uri-format-fragment branch from 3506a4d to 3cb943b Compare June 22, 2026 08:32
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.51%. Comparing base (64c4277) to head (3cb943b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #269      +/-   ##
==========================================
+ Coverage   86.50%   86.51%   +0.01%     
==========================================
  Files          18       18              
  Lines        2467     2469       +2     
==========================================
+ Hits         2134     2136       +2     
  Misses        230      230              
  Partials      103      103              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@fredbi fredbi merged commit 06b6bb0 into go-openapi:master Jun 22, 2026
23 checks passed
patchwright added a commit to patchwright/wildlint that referenced this pull request Jun 24, 2026
Distilled from deepdiff#602: a function written assuming datetime.datetime
that calls .replace(second=0, microsecond=0) unconditionally crashes on a
bare datetime.date, because datetime is a subclass of date — so any
isinstance(x, date) dispatch admits datetimes but fails to keep bare dates
out, and a replace() written for datetime raises TypeError on a date.

Ships that check two ways, mirroring WP001:
- find_date_kwargs(): dependency-free runtime checker that probes fn with a
  bare date and time, recording only TypeError/AttributeError that cite a
  time-only field (hour/minute/second/microsecond/nanosecond/tzinfo/fold) —
  the signature of this class, not an unrelated crash. Verified to bite a
  faithful reproduction of the deepdiff#602 truncate and stay silent on a
  hasattr-guarded fix.
- DATE_KWARGS / --template date-time-kwargs: renders a paste-ready pytest
  module (auto-listed by the CLI alongside WP001).

Violation is generalized (mantissa/unit now Optional, branched __str__) so a
non-rollover property can carry an output+reason; the rollover path and its
tests are unchanged.

Also documents uri-fragment-as-userinfo (go-openapi/strfmt#269, merged) in
NON_GENERALIZED: probed against urllib.parse, rfc3986, yarl, furl, hyperlink
(2026-06-24) — every Python URI parser is RFC-3986-compliant and treats '#'
as the fragment delimiter, so the class is Go-specific and ships no Python
surface. No gap in WP numbering: date-time-kwargs is WP002.

42 tests green (was 31), ruff clean, twine check passes. v0.3.0.

Co-Authored-By: claude-flow <ruv@ruv.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

url parsing fails if front slash before fragment is missing and no path specified

2 participants