Skip to content

fix: handle GitHub URLs with slash-based branches and multi-dot spec files#2191

Open
benjamenhoffman wants to merge 1 commit intoasyncapi:masterfrom
benjamenhoffman:fix/github-url-and-extension-parsing
Open

fix: handle GitHub URLs with slash-based branches and multi-dot spec files#2191
benjamenhoffman wants to merge 1 commit intoasyncapi:masterfrom
benjamenhoffman:fix/github-url-and-extension-parsing

Conversation

@benjamenhoffman
Copy link
Copy Markdown

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:

https://github.com/org/repo/blob/feature/new-validation/spec.yaml

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.com URLs which naturally handle branch names with slashes:

https://raw.githubusercontent.com/org/repo/feature/new-validation/spec.yaml

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) → returned undefined causing crashes

Fix:

  • In SpecificationFile.ts: Use path.extname() which correctly extracts the last extension
  • In new/file.ts: Use .split(".").pop() which gets the last segment after dots

Test Plan

  • Verified regex correctly matches simple branch URLs: https://github.com/org/repo/blob/main/spec.yaml
  • Verified regex correctly matches slash-containing branch URLs: https://github.com/org/repo/blob/feature/new-validation/spec.yaml
  • Verified path.extname() correctly handles my.asyncapi.yaml.yaml
  • Verified path.extname() correctly handles asyncapi"" (empty)
  • Existing validation service tests still pass

Closes #1940

…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
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 8, 2026

⚠️ No Changeset found

Latest commit: 129e952

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

[BUG] CLI fails for GitHub URLs with slash-based branches and multi-dot spec files

1 participant