Fix RepositoryFormatException for repository names that start with a hyphen - #3083
Open
asaf-clover wants to merge 1 commit into
Open
Fix RepositoryFormatException for repository names that start with a hyphen#3083asaf-clover wants to merge 1 commit into
asaf-clover wants to merge 1 commit into
Conversation
In the nameWithOwner regex, the name-part class [a-z0-9.-_] contains the character range .-_ (0x2E-0x5F) rather than three literals, so the literal hyphen (0x2D) is not in the class. Repository names whose first character is '-' fail IsNameWithOwnerFormat, and search requests using the Repos collection throw RepositoryFormatException for repositories that are valid on GitHub. Introduced in octokit#1418, which appended '_' after the previously trailing literal '-'. Reorder the class to [a-z0-9_.-] so '.', '-', and '_' are all literals. Fixes octokit#3082 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
|
@G-Rath |
Author
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.
Fixes #3082
Problem
Search requests that use the
Reposcollection throwRepositoryFormatExceptionclient-side for repository names that start with a hyphen (e.g.myorg/-my-repo), even though such names are valid on GitHub and the server-side search API accepts the correspondingrepo:qualifier.Root cause
In the
nameWithOwnervalidation regex, the name-part character class[a-z0-9.-_]does not contain three literal punctuation characters —.-_is a character range (0x2E–0x5F). The literal-(0x2D) sits just below the range start, so it is not in the class, and any name whose first character is-fails to match right after the/(mid-name hyphens still pass only because the regex is unanchored).This regressed in #1418 (the fix for #1406, leading-underscore names): appending
_after the previously trailing literal-turned.-+_into the.-_range.Fix
Reorder the class so all three specials are literals —
.-_→_.-:Leading-hyphen names now validate; leading-underscore (#1406) and leading-dot (
.github) names keep working. As a side effect the accidental range no longer admits characters that can never appear in a repository name (/ : ; < = > ? @ [ \ ] ^), so the validation also becomes slightly stricter in the correct direction.Tests
StringExtensionsTests.TheIsNameWithOwnerFormatMethod— new theory covering leading-hyphen, leading-underscore, leading-dot, regular names, and invalid input.SearchClientTests.TestingTheRepoQualifier_RepoNameStartingWithHyphen— end-to-end:SearchIssuessendsrepo:octokit/-repo-starting-with-hypheninstead of throwing.Octokit.Testsunit suite: 4550 passed / 4 failed — the 4 failures are theCanPopulateObjectFromSerializedData(BinaryFormatter) tests, which fail identically on unmodifiedmainunder the .NET 10 runtime used locally (BinaryFormatter is disabled in .NET 9+); they are unrelated to this change.🤖 Generated with Claude Code