Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/net/github/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ export const parseGitHubRepositoryUrl = (githubUrl) => {
if (host !== 'github.com' && host !== 'raw.githubusercontent.com') {
throw new Error('Not a valid GitHub repository URL')
}
const match = url.pathname.match(`^/${pathParts.join('/')}$`)
if (match === null) {
const match = re.exec(url.pathname)
if (!match) {
throw new Error('Could not match GitHub repository URL')
}
if (!match.groups) {
throw new Error('GitHub repository URL does not expose named groups')
}
const {groups: {org, repo, branch, file}} = match
return {
url: url,
Expand Down
8 changes: 8 additions & 0 deletions src/net/github/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ describe('net/github/utils', () => {
expect(actual.ref).toEqual('main')
expect(actual.path).toEqual('haus.ifc')
})

it('throws an error if a match has no named capture groups', () => {
const execSpy = jest.spyOn(RegExp.prototype, 'exec')
execSpy.mockReturnValueOnce([''])
expect(() => parseGitHubRepositoryUrl('https://github.com/org/repo/blob/main/file.ifc'))
.toThrowError('GitHub repository URL does not expose named groups')
execSpy.mockRestore()
})
})


Expand Down
Loading