Skip to content

Commit

Permalink
fix pathname usage
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jan 21, 2025
1 parent a310c88 commit e4c8791
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions web_src/js/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ test('parseIssueHref', () => {

test('parseRepoOwnerPathInfo', () => {
expect(parseRepoOwnerPathInfo('/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo'});
expect(parseRepoOwnerPathInfo('/owner/repo/issues/new?query')).toEqual({ownerName: 'owner', repoName: 'repo'});
expect(parseRepoOwnerPathInfo('/owner/repo/releases')).toEqual({ownerName: 'owner', repoName: 'repo'});
expect(parseRepoOwnerPathInfo('/other')).toEqual({});
window.config.appSubUrl = '/sub';
expect(parseRepoOwnerPathInfo('/sub/owner/repo/issues/new#hash')).toEqual({ownerName: 'owner', repoName: 'repo'});
expect(parseRepoOwnerPathInfo('/sub/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo'});
expect(parseRepoOwnerPathInfo('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo'});
window.config.appSubUrl = '';
});
Expand Down
3 changes: 1 addition & 2 deletions web_src/js/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export function parseIssueHref(href: string): IssuePathInfo {
export function parseRepoOwnerPathInfo(pathname: string): RepoOwnerPathInfo {
const appSubUrl = window.config.appSubUrl;
if (appSubUrl && pathname.startsWith(appSubUrl)) pathname = pathname.substring(appSubUrl.length);
const path = (pathname || '').replace(/[#?].*$/, '');
const [_, ownerName, repoName] = /([^/]+)\/([^/]+)/.exec(path) || [];
const [_, ownerName, repoName] = /([^/]+)\/([^/]+)/.exec(pathname) || [];
return {ownerName, repoName};
}

Expand Down

0 comments on commit e4c8791

Please sign in to comment.