Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/url: ResolveReference ignores Opaque value #66084

Open
santhosh-tekuri opened this issue Mar 4, 2024 · 3 comments · May be fixed by #66415
Open

net/url: ResolveReference ignores Opaque value #66084

santhosh-tekuri opened this issue Mar 4, 2024 · 3 comments · May be fixed by #66415
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@santhosh-tekuri
Copy link
Contributor

Go version

go version go1.21.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/santhosh/Library/Caches/go-build'
GOENV='/Users/santhosh/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/santhosh/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/santhosh/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Volumes/Backup/github.com/santhosh-tekuri/jsonschema/cmd/jv/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/3s/8z1m0ns10s1bdl3bl1dx8nbh0000gn/T/go-build2151327207=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

run the code https://go.dev/play/p/QndsQIeIA73

What did you see happen?

prints: urn:#abcd

What did you expect to see?

print: urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed#abcd

@mknyszek mknyszek added this to the Backlog milestone Mar 4, 2024
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 4, 2024
@mknyszek
Copy link
Contributor

mknyszek commented Mar 4, 2024

CC @neild

@fmata97
Copy link

fmata97 commented Mar 4, 2024

I was able to reproduce the issue and from my research on the reference resolution algorithm specified in RFC 3986 section 5.2, the given example should, in fact, print urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed#abcd.
Since the base URI ("urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed#xxx") is opaque and the reference doesn't have a scheme defined neither an authority section, the result should be the base scheme and opaque followed by the reference query and/or fragment.

The code for ResolveReference doesn't support this case, as it ignores the base opaque value (u.Opaque):

go/src/net/url/url.go

Lines 1114 to 1118 in b38b1b2

// The "abs_path" or "rel_path" cases.
url.Host = u.Host
url.User = u.User
url.setPath(resolvePath(u.EscapedPath(), ref.EscapedPath()))
return &url

I believe the solution would be to check for this case before reaching the referenced piece of code and setting the URI parameters accordingly.
If this sounds all good, feel free to assign me the issue as I would like to fix it with a PR.

fmata97 added a commit to fmata97/go that referenced this issue Mar 19, 2024
…thod

The current implementation doesn't resolve as per spec RFC 3986 the case where the base URL has an opaque value, and the reference doesn't have either a scheme, authority or path. Currently, this specific case falls back to the "abs_path" or "rel_path" cases, where the final path results of the base_path being resolved relatively to the reference's, but since the opaque value is stored independently, it needs a case of its own.

The algorith for resolving references is defined in RFC 3986 section 5.2.2:
https://www.rfc-editor.org/rfc/rfc3986.html#section-5.2.2

Fixes golang#66084
@gopherbot
Copy link

Change https://go.dev/cl/572915 mentions this issue: net/url: fix missing handling for opaque value in ResolveReference method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants