fix: resolve GitHub URLs with slash-based branches and multi-dot filenames#2209
Open
tdnguyenND wants to merge 1 commit into
Open
fix: resolve GitHub URLs with slash-based branches and multi-dot filenames#2209tdnguyenND wants to merge 1 commit into
tdnguyenND wants to merge 1 commit into
Conversation
…names
Bug 1 (validation.service.ts): The previous regex used `([^\/]+)` for the
branch segment, which stops at the first `/`. Branch names like
`feature/my-fix` were parsed incorrectly, causing 404 errors when fetching
the file. Replace single-URL conversion with `generateGitHubApiCandidates`
that produces every possible branch/path split and retries on 404, trying
the shortest branch first (most common case). Non-404 errors (auth, server)
propagate immediately without retrying.
Also moves auth-header population before the GitHub blob URL handling so
that credentials are available on all retry attempts.
Bug 2 (SpecificationFile.ts): `name.split('.')[1]` returns the second
dot-separated segment, which is wrong for filenames like `my.asyncapi.yaml`
(returns `asyncapi` instead of `yaml`). Replace with
`path.extname(name).slice(1).toLowerCase()` which always returns the true
file extension.
Fixes asyncapi#1940
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 1ba6f86 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
2 tasks
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.



Summary
Fixes two parsing bugs from #1940.
Bug 1 — GitHub URL with slash-based branch names
Root cause: The previous implementation used a regex with
([^\/]+)for thebranch segment, which stops at the first
/. A branch likefeature/my-fixwas parsed as branch=
featureand path=my-fix/spec.yaml, producing anincorrect GitHub API URL that returned 404.
Why this is genuinely hard to fix with a simple regex change:
The URL
https://github.com/org/repo/blob/feature/new-validation/spec.yamlis structurally ambiguous — you cannot tell from the URL alone where the branch
ends and the file path begins. Changing
([^\/]+)to(.+?)(as done in severalother PRs) still uses a lazy match that resolves to the shortest branch, i.e. the
same broken behaviour.
Fix: Replace
convertGitHubWebUrlwithgenerateGitHubApiCandidates, whichproduces every possible branch/path split ordered from shortest branch to longest.
The
read()function tries each candidate and retries only on HTTP 404. Othererrors (authentication failures, server errors) propagate immediately without
retrying. This correctly handles all branch naming conventions without any
hard-coded heuristics.
Bonus fix: Auth headers are now populated before the candidate-retry loop,
ensuring credentials are available on all retry attempts. The original code
fetched the auth config but applied it to
headersafter the blob URL had beenconverted — a race that was benign before this change but is now important.
Bug 2 — Wrong extension for multi-dot filenames
Root cause:
name.split('.')[1]returns the second segment, which is wrongfor filenames like
my.asyncapi.yaml(returnsasyncapi) and crashes forfilenames without a dot (returns
undefined).Fix:
path.extname(name).slice(1).toLowerCase()correctly returns thetrailing extension in all cases.
pathis already imported.Test plan
asyncapi validate https://github.com/org/repo/blob/feature/my-fix/spec.yamlresolves correctlyasyncapi validate my.asyncapi.yamlno longer rejects the filenpm run test:unit)npm run buildsucceeds