internal/cloudstorage: handle Windows volume paths - #826
Open
arpitjain099 wants to merge 1 commit into
Open
Conversation
parseBucketAndPrefix passed the raw path to url.Parse, which interprets a Windows absolute path such as "C:\path\to\file" as a URL with the single-letter scheme "c". The local-file branch was then skipped and the volume was mishandled, so cmd/enumerate_github/marker tests failed on Windows where t.TempDir() returns volume-rooted absolute paths. Detect a single-letter drive followed by a volume separator before parsing and treat it as an absolute local filesystem path, normalising backslashes to forward slashes so path.Split works on any host OS. Real scheme URLs (gs://, s3://, file://, mem://) are unaffected. Adds table-driven tests covering backslash, forward-slash and lowercase drive-letter forms. Closes ossf#337 Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
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.
Summary
internal/cloudstorage.parseBucketAndPrefixpasses the raw destination tourl.Parse. On a Windows absolute path likeC:\path\to\file,url.Parsereads the drive letter as a single-character URL scheme (c), andurl.URL.IsAbs()then returns true. That skips the scheme-less local-file branch entirely, so the volume is never recognised as a filesystem path andpath.Splitoperates on the wrong value.This is what makes the
cmd/enumerate_github/markertests fail on Windows, wheret.TempDir()hands back volume-rooted absolute paths (#337).Reproduction
url.Parseon a volume path:Because
IsAbs()is true, the value is treated as a cloud bucket with schemecinstead of a local file.Fix
Detect a single-letter drive followed by a volume separator (
hasWindowsVolume) before parsing. When present, build the URL as an absolute local filesystem path, normalising backslashes to forward slashes sopath.Splitbehaves the same regardless of the host OS, and prefixing/so the volume stays in the URL path rather than being parsed as a host.Real scheme URLs (
gs://,s3://,file://,mem://) take the existingurl.Parsepath and are unchanged.Before / after
For
C:\path\to\file:c, bucket mis-parsed, prefix wrong.file:///C:/path/to/?metadata=skip, prefixfile. This mirrors the existing handling of a POSIX absolute path like/path/to/file(bucketfile:///path/to/?metadata=skip, prefixfile).Tests
Added a table-driven
TestParseBucketAndPrefixWindowsVolumecovering the backslash, forward-slash, and lowercase-drive-letter forms. The case fails on the current source (drive letter parsed as scheme) and passes with the fix. The existing local-path and scheme-URL tests continue to pass.go test ./internal/cloudstorage/is green andgo build ./...succeeds. These tests run on any OS, so they guard the Windows behaviour from a Linux CI runner.Closes #337