Skip to content

fix: handle slashed branch names and multi-dot filenames in GitHub URL parsing#2150

Open
selenaalpha77-sketch wants to merge 2 commits intoasyncapi:masterfrom
selenaalpha77-sketch:fix/issue-1940
Open

fix: handle slashed branch names and multi-dot filenames in GitHub URL parsing#2150
selenaalpha77-sketch wants to merge 2 commits intoasyncapi:masterfrom
selenaalpha77-sketch:fix/issue-1940

Conversation

@selenaalpha77-sketch
Copy link
Copy Markdown

What

Fixes two validation bugs from issue 1940.

1. GitHub URL Parsing - slashed branch names

The previous regex for the branch segment rejected valid URLs like:
https://github.com/org/repo/blob/feature/new-validation/spec.yaml

convertGitHubWebUrl() now converts github.com blob URLs to raw.githubusercontent.com URLs. The raw URL format preserves the exact ref+path structure without needing to split the branch from the file path. The existing resolver already handles raw.githubusercontent.com URLs with the correct Accept header.

2. File Extension Detection - multi-dot filenames

name.split('.')[1] returns the second segment, not the extension. For my.asyncapi.yaml it returns asyncapi instead of yaml, causing the file to be rejected.

Both fileExists() in SpecificationFile.ts and the new file command now use name.lastIndexOf('.') to get the actual extension. Also handles filenames without any extension safely.

Changes

  • src/domains/services/validation.service.ts: Rewrote convertGitHubWebUrl() to produce raw.githubusercontent.com URLs; exported for unit testing
  • src/domains/models/SpecificationFile.ts: Fixed extension detection in fileExists()
  • src/apps/cli/commands/new/file.ts: Fixed extension detection
  • test/unit/services/validation.service.test.ts: Added 9 unit tests covering all fixed cases

…rsing

- convertGitHubWebUrl now converts github.com blob URLs to
  raw.githubusercontent.com URLs instead of api.github.com.
  This correctly handles branch names containing slashes
  (e.g. feature/new-validation) and deeply nested file paths
  without needing to split the branch from the file path, since
  raw.githubusercontent.com preserves the exact ref+path structure.

- fileExists() in SpecificationFile.ts and the new-file command
  now use name.lastIndexOf('.') to extract the file extension,
  correctly handling filenames with multiple dots (e.g. my.asyncapi.yaml)
  and filenames without any extension.

- Exports convertGitHubWebUrl for unit testing and adds comprehensive
  unit tests covering slashed branches, multi-dot filenames, fragments,
  non-GitHub URLs, and subdirectory paths.

Fixes asyncapi#1940
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 25, 2026

🦋 Changeset detected

Latest commit: 5eae4fe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Patch

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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant