Skip to content

fix: GitHub URL parsing and file extension detection for issue #1940#2141

Open
597226617 wants to merge 1 commit intoasyncapi:masterfrom
597226617:master
Open

fix: GitHub URL parsing and file extension detection for issue #1940#2141
597226617 wants to merge 1 commit intoasyncapi:masterfrom
597226617:master

Conversation

@597226617
Copy link
Copy Markdown

Description

This PR fixes two bugs reported in issue #1940:

Bug 1: GitHub URL Parsing with Slash-based Branch Names

Problem: The CLI failed to parse GitHub URLs when branch names contained slashes (e.g., feature/new-validation).

Root Cause: The regex pattern assumed branch names do not contain /:

const githubWebPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)$/;
//                                                                ^^^^^^^^
//                                                                Only matches non-slash characters

Fix: Updated the regex to capture the entire branch path (including slashes):

const githubWebPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/(.+)\/([^\/]+)$/;
//                                                                ^^^^
//                                                                Matches any characters (including slashes)

Bug 2: File Extension Detection for Multi-dot Filenames

Problem: Files with multiple dots in the name (e.g., my.asyncapi.yaml) were incorrectly parsed.

Root Cause: Using name.split('.')[1] returns the second segment, not the extension:

'my.asyncapi.yaml'.split('.') // ['my', 'asyncapi', 'yaml']
//                               [1] = 'asyncapi' (WRONG!)

Fix: Use path.extname() which correctly handles multi-dot filenames:

const extension = path.extname(name).slice(1); // 'yaml' ✅

Testing

Both fixes have been tested with multiple test cases:

GitHub URL Parsing Tests

  • https://github.com/org/repo/blob/feature/new-validation/spec.yaml
  • https://github.com/org/repo/blob/main/spec.yaml
  • https://github.com/org/repo/blob/feature/branch/name/spec.yaml

File Extension Tests

  • asyncapi.yamlyaml
  • my.asyncapi.yamlyaml
  • test.v2.asyncapi.yamlyaml
  • file.with.many.dots.jsonjson

Related Issue

Closes #1940

…pi#1940

- Fix GitHub URL regex to support branch names with slashes (e.g., feature/new-validation)
- Fix file extension detection to handle files with multiple dots (e.g., my.asyncapi.yaml) using path.extname()

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

changeset-bot Bot commented Apr 23, 2026

⚠️ No Changeset found

Latest commit: 481f690

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

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