Skip to content

Fix RepositoryFormatException for repository names that start with a hyphen - #3083

Open
asaf-clover wants to merge 1 commit into
octokit:mainfrom
asaf-clover:fix/allow-repo-names-starting-with-hyphen
Open

Fix RepositoryFormatException for repository names that start with a hyphen#3083
asaf-clover wants to merge 1 commit into
octokit:mainfrom
asaf-clover:fix/allow-repo-names-starting-with-hyphen

Conversation

@asaf-clover

Copy link
Copy Markdown

Fixes #3082

Problem

Search requests that use the Repos collection throw RepositoryFormatException client-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 corresponding repo: qualifier.

Root cause

In the nameWithOwner validation 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 — .-__.-:

-        static readonly Regex nameWithOwner = new Regex("[a-z0-9.-]{1,}/[a-z0-9.-_]{1,}",
+        static readonly Regex nameWithOwner = new Regex("[a-z0-9.-]{1,}/[a-z0-9_.-]{1,}",

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: SearchIssues sends repo:octokit/-repo-starting-with-hyphen instead of throwing.
  • Full Octokit.Tests unit suite: 4550 passed / 4 failed — the 4 failures are the CanPopulateObjectFromSerializedData (BinaryFormatter) tests, which fail identically on unmodified main under the .NET 10 runtime used locally (BinaryFormatter is disabled in .NET 9+); they are unrelated to this change.

🤖 Generated with Claude Code

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>
@asaf-clover

Copy link
Copy Markdown
Author

@G-Rath
Hi,
Can you please help me push this PR.
Thanks!

@asaf-clover

Copy link
Copy Markdown
Author

@octokitbot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 Triage

Development

Successfully merging this pull request may close these issues.

[BUG]: SearchIssuesRequest throws RepositoryFormatException for repository names that start with a hyphen

2 participants