fix: prevent panic when BaseURL has empty scheme in normalizeRemoteURL#579
Open
toller892 wants to merge 1 commit into
Open
fix: prevent panic when BaseURL has empty scheme in normalizeRemoteURL#579toller892 wants to merge 1 commit into
toller892 wants to merge 1 commit into
Conversation
normalizeRemoteURL unconditionally overwrote the remote URL's scheme with the BaseURL's scheme, even when the BaseURL had an empty scheme. This caused the remote URL's scheme to be cleared, leading to a (nil, nil) return at the empty-scheme check. Callers like consumeAdaptedFile then passed nil to io.ReadAll, causing an unrecoverable panic. Changes: - normalizeRemoteURL now skips normalization when BaseURL lacks host or scheme - OpenWithContext returns an error instead of (nil, nil) when scheme is empty (defense-in-depth) - Added regression tests for empty-scheme BaseURL and empty root URL scenarios Fixes pb33f#578
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #579 +/- ##
==========================================
- Coverage 99.72% 99.71% -0.01%
==========================================
Files 280 280
Lines 33853 33855 +2
==========================================
- Hits 33761 33760 -1
- Misses 55 57 +2
- Partials 37 38 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
One single line.. you can do it! |
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.
Description
normalizeRemoteURLunconditionally overwrites the remote URL's scheme with theBaseURL's scheme, even whenBaseURLhas an empty scheme. This clears the remote URL's scheme, leading to a(nil, nil)return at the empty-scheme check inOpenWithContext(line 588-590). Callers likeconsumeAdaptedFilethen passniltoio.ReadAll, causing an unrecoverable panic.In some call chains this happens from a
singleflight.Group.Dogoroutine, making it impossible for the calling program to recover even withrecover.Changes
normalizeRemoteURL: Skip normalization entirely whenBaseURLlacks a host or scheme. This prevents the remote URL's scheme from being cleared by a malformed base URL.OpenWithContext: Return an error instead of(nil, nil)when the scheme is empty after normalization (defense-in-depth). This preventsio.ReadAll(nil)panics even if some other code path produces an empty scheme.Regression tests: Added
TestNormalizeRemoteURL_PreservesSchemeWhenBaseURLHasEmptyScheme,TestNormalizeRemoteURL_OverwritesSchemeWhenBaseURLHasScheme,TestNormalizeRemoteURL_NoOpWhenBaseURLIsEmpty, andTestOpenWithContext_ReturnsErrorOnEmptyScheme.Testing
All existing tests pass, including
TestNewRemoteFS_BasicCheck_NoScheme(updated to expect an error instead ofnilwhen the root URL is empty, since normalization is now a no-op and the URL is fetched normally).Fixes #578