Skip to content

Commit f94a826

Browse files
authored
Fix some unescaped regex strings (#6979)
1 parent 7330a7f commit f94a826

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/github/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Resource } from '../common/resources';
1919
import { GITHUB_ENTERPRISE, OVERRIDE_DEFAULT_BRANCH, PR_SETTINGS_NAMESPACE, URI } from '../common/settingKeys';
2020
import * as Common from '../common/timelineEvent';
2121
import { DataUri, toOpenIssueWebviewUri, toOpenPullRequestWebviewUri } from '../common/uri';
22-
import { gitHubLabelColor, stringReplaceAsync, uniqBy } from '../common/utils';
22+
import { escapeRegExp, gitHubLabelColor, stringReplaceAsync, uniqBy } from '../common/utils';
2323
import { OctokitCommon } from './common';
2424
import { FolderRepositoryManager, PullRequestDefaults } from './folderRepositoryManager';
2525
import { GitHubRepository, ViewerPermission } from './githubRepository';
@@ -309,7 +309,7 @@ export function convertRESTHeadToIGitHubRef(head: OctokitCommon.PullsListRespons
309309

310310
async function transformHtmlUrlsToExtensionUrls(body: string, githubRepository: GitHubRepository): Promise<string> {
311311
const issueRegex = new RegExp(
312-
`href="https?:\/\/${githubRepository.remote.gitProtocol.url.authority}\\/${githubRepository.remote.owner}\\/${githubRepository.remote.repositoryName}\\/(issues|pull)\\/([0-9]+)"`);
312+
`href="https?:\/\/${escapeRegExp(githubRepository.remote.gitProtocol.url.authority)}\\/${escapeRegExp(githubRepository.remote.owner)}\\/${escapeRegExp(githubRepository.remote.repositoryName)}\\/(issues|pull)\\/([0-9]+)"`);
313313
return stringReplaceAsync(body, issueRegex, async (match: string, issuesOrPull: string, number: string) => {
314314
if (issuesOrPull === 'issues') {
315315
return `href="${(await toOpenIssueWebviewUri({ owner: githubRepository.remote.owner, repo: githubRepository.remote.repositoryName, issueNumber: Number(number) })).toString()}""`;

src/issues/currentIssue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
USE_BRANCH_FOR_ISSUES,
1616
WORKING_ISSUE_FORMAT_SCM,
1717
} from '../common/settingKeys';
18+
import { escapeRegExp } from '../common/utils';
1819
import { FolderRepositoryManager, PullRequestDefaults } from '../github/folderRepositoryManager';
1920
import { GithubItemStateEnum } from '../github/interface';
2021
import { IssueModel } from '../github/issueModel';
@@ -218,7 +219,7 @@ export class CurrentIssue extends Disposable {
218219
undefined,
219220
await this.getUser(),
220221
);
221-
const branchNameMatch = this._branchName?.match(new RegExp('^(' + branchNameConfig + ')(_)?(\\d*)'));
222+
const branchNameMatch = this._branchName?.match(new RegExp('^(' + escapeRegExp(branchNameConfig) + ')(_)?(\\d*)'));
222223
if ((createBranchConfig === 'on')) {
223224
const branch = await this.getBranch(this._branchName!);
224225
if (!branch) {

0 commit comments

Comments
 (0)