Skip to content

Conversation

@PascalThuet
Copy link
Contributor

@PascalThuet PascalThuet commented Jan 24, 2026

Description:

Fix a bug where repository names ending with a hyphen (e.g., my-repo-) would have the trailing hyphen stripped when parsing the URL, causing 404 errors when trying to access the repository via the GitHub API.

Root cause: The getRepoURLParts() function reconstructed the URL via url.URL.String() and then re-parsed it by splitting on /. This process could lose trailing special characters in certain edge cases.

Fix: Use repoURL.Host and repoURL.Path directly instead of reconstructing via String(), which preserves the original path including any trailing hyphens.

Example of the bug:

Input URL: https://github.com/MYORG/my-repo-name-
Expected API call: GET /repos/MYORG/my-repo-name-
Actual API call:   GET /repos/MYORG/my-repo-name  (missing trailing hyphen)

Fixes #4679

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Testing notes:

New unit tests added in TestGetRepoURLPartsWithTrailingHyphen covering edge cases for trailing hyphens in repository names (https, ssh, multiple hyphens, single - repo name).

Fix a bug where repository names ending with a hyphen (e.g., "my-repo-")
would have the trailing hyphen stripped when parsing the URL, causing
404 errors when trying to access the repository via the GitHub API.

The issue was in getRepoURLParts() which reconstructed the URL via
url.URL.String() and then re-parsed it. This process could lose
trailing special characters in some cases.

The fix uses repoURL.Host and repoURL.Path directly instead of
reconstructing via String(), which preserves the original path
including any trailing hyphens.

Fixes trufflesecurity#4679
Copy link
Contributor

@rosecodym rosecodym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you!

@rosecodym rosecodym merged commit 37994c5 into trufflesecurity:main Jan 26, 2026
13 checks passed
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.

GitHub scan returns 404 for repositories with trailing hyphen in name

3 participants