Skip to content

Reject a whitespace-only repository name from a host - #81

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/reject-whitespace-repository-name
Aug 25, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/reject-whitespace-repository-name

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

A host returning a repository name of only whitespace currently throws an ArgumentException out of GetRepositoriesAsync, which is outside the failure surface that method documents. A caller writing catch (GitHostingException) misses it.

Why it happens

GitProvider.ToLocalRepositoryPath rejects a leaf that is empty, ., or .., but tests string.IsNullOrEmpty, so whitespace survives and Path.Combine accepts it. The exception then comes from somewhere else entirely: LocalPath is assigned before Name in the object initializer, so the path is built successfully and GitRepositoryName's own [HasNonWhitespaceContent] validation throws a moment later.

The result is two different failure shapes for one input, decided by field initialization order rather than by design.

The change

ToLocalRepositoryPath rejects a whitespace-only leaf alongside the cases it already rejected, throwing GitHostingRequestException naming the provider and the offending value, before Name is ever assigned. Both providers now fail the same way on the same input.

One word of logic, one <exception> doc correction, and a test in each provider's test file beside the existing rooted and traversal cases.

Verification

Build 0 warnings and 0 errors. Suite 481/481 passing, 0 skipped, run under KTSU_GIT_INTEGRATION_TESTS_REQUIRED=1 GIT_CONFIG_NOSYSTEM=1 so the integration tier is exercised the way the POSIX runners see it.

Mutation-checked: reverting the guard makes both new tests fail, and the failure they produce is the ArgumentException described above rather than a silent pass, which is the behaviour this fixes.

Context

Follow-up to #80. This was found while probing the path-containment invariant added there, not by the automated reviewer. Containment itself was never at risk, since a whitespace path stays under the current directory. This is about the error contract.

A host returning a repository name of only whitespace produced an
ArgumentException from GitRepositoryName's own validation rather than a
GitHostingException, because LocalPath is assigned before Name in the
object initializer and Path.Combine accepts the whitespace segment. That
exception escapes the failure surface these methods document, so a caller
catching GitHostingException misses it entirely.

ToLocalRepositoryPath now rejects a whitespace-only leaf alongside an
empty, "." or ".." one, throwing GitHostingRequestException before Name is
assigned. Both providers fail the same way on the same input.
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 5a96eb7 into main Aug 25, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/reject-whitespace-repository-name branch August 25, 2026 05:54
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.

1 participant