Skip to content

fix: support slash-based branch names in GitHub URLs and multi-dot file extensions#2206

Open
XuanYuandp wants to merge 2 commits into
asyncapi:masterfrom
XuanYuandp:fix/github-url-parsing-and-extension-detection
Open

fix: support slash-based branch names in GitHub URLs and multi-dot file extensions#2206
XuanYuandp wants to merge 2 commits into
asyncapi:masterfrom
XuanYuandp:fix/github-url-parsing-and-extension-detection

Conversation

@XuanYuandp
Copy link
Copy Markdown

What this does

Fixes #1940 — Two validation bugs causing valid inputs to fail.

Bug 1: GitHub URL Parsing

The regex assumed branch names don't contain /. URLs like github.com/org/repo/blob/feature/new-validation/spec.yaml were incorrectly parsed, extracting only feature as the branch.

Fix: Changed regex to capture everything after /blob/, then uses a heuristic to find the correct branch/path split point.

Bug 2: File Extension Detection

Used name.split('.')[1] which returns the wrong segment for multi-dot filenames like my.asyncapi.yaml (returns asyncapi instead of yaml).

Fix: Changed to name.split('.').pop() to always get the last segment.

Files changed

  • src/domains/services/validation.service.ts — Fix GitHub URL regex
  • src/domains/models/SpecificationFile.ts — Fix extension detection
  • src/apps/cli/commands/new/file.ts — Fix extension detection
  • test/unit/services/validation.service.test.ts — Add test for slash-based branch names

Testing

All 9 tests passing including new test for slash-based branch name parsing.

Part of MICROGRANT Program 2026-05 (references #1940).

…le extensions

Fixes asyncapi#1940

Two bugs fixed:

1. GitHub URL parsing regex assumed branch names don't contain '/'.
   This caused URLs like github.com/org/repo/blob/feature/new-validation/spec.yaml
   to be incorrectly parsed, extracting only 'feature' as the branch name.
   Fixed by using a heuristic to find the correct branch/path split point.

2. File extension detection used `name.split('.')[1]` which returns the
   wrong segment for multi-dot filenames like `my.asyncapi.yaml`.
   Fixed by using `.pop()` to always get the last segment (actual extension).

Files changed:
- src/domains/services/validation.service.ts: Fix GitHub URL regex
- src/domains/models/SpecificationFile.ts: Fix extension detection
- src/apps/cli/commands/new/file.ts: Fix extension detection
- test/unit/services/validation.service.test.ts: Add test for slash branches
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: 0f85c3d

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 Opus 4.7 <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.

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

1 participant