Skip to content

Commit 481f690

Browse files
author
mini
committed
fix: GitHub URL parsing and file extension detection for issue #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 #1940
1 parent f67a6ad commit 481f690

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/domains/models/SpecificationFile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export async function fileExists(name: string): Promise<boolean> {
237237
return true;
238238
}
239239

240-
const extension = name.split('.')[1];
240+
// Use path.extname to correctly handle files with multiple dots (e.g., my.asyncapi.yaml)
241+
const extension = path.extname(name).slice(1);
241242

242243
const allowedExtenstion = ['yml', 'yaml', 'json'];
243244

src/domains/services/validation.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ const convertGitHubWebUrl = (url: string): string => {
6969
const urlWithoutFragment = url.split('#')[0];
7070

7171
// Handle GitHub web URLs like: https://github.com/owner/repo/blob/branch/path
72+
// Note: branch name can contain slashes (e.g., feature/new-validation)
7273
// eslint-disable-next-line no-useless-escape
73-
const githubWebPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)$/;
74+
const githubWebPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/(.+)\/([^\/]+)$/;
7475
const match = urlWithoutFragment.match(githubWebPattern);
7576

7677
if (match) {

0 commit comments

Comments
 (0)