fix: Support slash-based branch names and multi-dot spec filenames (fixes #1940)#2154
Open
drsophieservice-lang wants to merge 1 commit into
Conversation
…ixes asyncapi#1940) - Replace greedy regex in convertGitHubWebUrl to handle branches with slashes by converting to raw.githubusercontent.com format instead of GitHub API format - Replace name.split('.')[1] with path.extname() in fileExists() to correctly extract the last extension from filenames with multiple dots - Add test file test/github-url-parsing.test.ts with 14 test cases
|
|
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
This PR fixes two bugs in the AsyncAPI CLI that caused valid inputs to be rejected:
feature/new-validation) were parsed incorrectly, leading to 404 errors.my.asyncapi.yaml) had the wrong extension extracted, causing valid files to be rejected.Changes
src/domains/services/validation.service.tsBug (before):
The third capture group
([^\/]+)stopped at the first/in branch names. For a URL likehttps://github.com/org/repo/blob/feature/new-validation/spec.yaml, the branch was incorrectly parsed asfeatureinstead offeature/new-validation.Fix (after):
Since it is impossible to reliably split a branch name from a file path using only regex (when branches contain slashes), we convert to
raw.githubusercontent.comformat instead, which accepts the combinedbranch/pathstring directly.src/domains/models/SpecificationFile.tsBug (before):
For a filename like
my.asyncapi.yaml,split('.')[1]returnsasyncapiinstead ofyaml.Fix (after):
path.extname('my.asyncapi.yaml')correctly returns.yaml.Test Cases
New test file:
test/github-url-parsing.test.tswith 14 test cases.GitHub URL Parsing
…/blob/main/spec.yaml…?ref=mainraw.githubusercontent.com/…/main/spec.yaml…/blob/feature/new-validation/spec.yaml…?ref=feature(404)raw.githubusercontent.com/…/feature/new-validation/spec.yaml…/blob/release/v2/beta/spec/asyncapi.yaml…?ref=release(404)raw.githubusercontent.com/…/release/v2/beta/spec/asyncapi.yaml…/blob/feat/issue-42/docs/api/spec.yaml#L10File Extension Detection
asyncapi.yamlyamlyamlmy.asyncapi.yamlasyncapiyamlspec.v2.jsonv2jsonasyncapi(no ext)undefined(crash risk)''(safe)Testing
Related Issues
Closes #1940