fix: handle GitHub URLs with slash-based branches and multi-dot spec files#2191
Open
benjamenhoffman wants to merge 1 commit intoasyncapi:masterfrom
Open
fix: handle GitHub URLs with slash-based branches and multi-dot spec files#2191benjamenhoffman wants to merge 1 commit intoasyncapi:masterfrom
benjamenhoffman wants to merge 1 commit intoasyncapi:masterfrom
Conversation
…files Fixes two CLI validation bugs: 1. GitHub URL Parsing: The regex for parsing GitHub blob URLs assumed branch names do not contain slashes, causing failures for valid URLs like https://github.com/org/repo/blob/feature/new-validation/spec.yaml. Fixed by converting to raw.githubusercontent.com URLs which naturally handle branch names with slashes without needing to split branch/path. 2. File Extension Detection: Used name.split('.')[1] which only gets the first part after the dot, failing for multi-dot filenames like my.asyncapi.yaml (returned 'asyncapi' instead of 'yaml'). Fixed by using path.extname() in SpecificationFile.ts and .pop() in new/file.ts. Closes asyncapi#1940
|
|
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 CLI validation bugs reported in #1940:
1. GitHub URL Parsing
The regex for parsing GitHub blob URLs assumed branch names do not contain slashes (
/), causing failures for valid URLs like:Fix: Instead of trying to split the branch from the path at the regex level (which is impossible since both can contain slashes), convert GitHub blob URLs to
raw.githubusercontent.comURLs which naturally handle branch names with slashes:This also eliminates the need for the GitHub Contents API call, simplifying the code path.
2. File Extension Detection
Used
name.split(".")[1]which only gets the first part after the dot, failing for multi-dot filenames:my.asyncapi.yaml→ returned"asyncapi"instead of"yaml"asyncapi(no extension) → returnedundefinedcausing crashesFix:
SpecificationFile.ts: Usepath.extname()which correctly extracts the last extensionnew/file.ts: Use.split(".").pop()which gets the last segment after dotsTest Plan
https://github.com/org/repo/blob/main/spec.yamlhttps://github.com/org/repo/blob/feature/new-validation/spec.yamlpath.extname()correctly handlesmy.asyncapi.yaml→.yamlpath.extname()correctly handlesasyncapi→""(empty)Closes #1940