Skip to content

Commit 341bcf7

Browse files
authored
Use regex groups (#8097)
1 parent d61254b commit 341bcf7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- **Strictness**: Some strictness is disabled in `tsconfig.base.json` (e.g., `strictNullChecks: false`), but new code should avoid unsafe patterns.
66
- **Testing**: Place tests under `src/test`. Do not include test code in production files.
77
- **Localization**: Use `%key%` syntax for strings that require localization. See `package.nls.json`.
8+
- **Regular Expressions**: Use named capture groups for clarity when working with complex regex patterns.
89

910
## Extension-Specific Practices
1011
- **VS Code API**: Use the official VS Code API for all extension points. Register commands, views, and menus via `package.json`.

src/common/uri.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,11 @@ export function fromOpenOrCheckoutPullRequestWebviewUri(uri: vscode.Uri): OpenPu
690690
const uriParam = queryParams.get('uri');
691691
if (uriParam) {
692692
// Parse the GitHub PR URL - match only exact format ending with the PR number
693-
const match = uriParam.match(/^https?:\/\/github\.com\/([^\/]+)\/([^\/]+)\/pull\/(\d+)$/);
694-
if (match) {
695-
const [, owner, repo, pullRequestNumber] = match;
693+
// Use named regex groups for clarity
694+
const prUrlRegex = /^https?:\/\/github\.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/pull\/(?<pullRequestNumber>\d+)$/;
695+
const match = prUrlRegex.exec(uriParam);
696+
if (match && match.groups) {
697+
const { owner, repo, pullRequestNumber } = match.groups;
696698
const params = {
697699
owner,
698700
repo,

0 commit comments

Comments
 (0)