Skip to content

Commit 7e138b4

Browse files
Copilotfregante
andcommitted
Revert regex optimizations, disable better-regex rule, update vite to v7.3.1
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
1 parent 7dc983e commit 7e138b4

File tree

3 files changed

+1516
-1840
lines changed

3 files changed

+1516
-1840
lines changed

index.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/* global document */
2+
/* eslint-disable unicorn/better-regex */
23
import reservedNames from 'github-reserved-names/reserved-names.json' with { type: 'json' };
34

4-
const patchDiffRegex = /\.(patch|diff)$/;
5-
const releaseRegex = /^releases\/tag\/([^/]+)/;
6-
const labelRegex = /^labels\/([^/]+)/;
7-
const compareRegex = /^compare\/([^/]+)/;
8-
const pullRegex = /^pull\/(?<pull>\d+)(?:\/(?<pullPage>[^/]+))?(?:\/(?<pullPartialStart>[\da-f]{40})\.\.(?<pullPartialEnd>[\da-f]{40}))?$/;
9-
const issueRegex = /^issues\/(\d+)$/;
10-
const commitRegex = /^commit\/([\da-f]{40})$/;
11-
const releaseArchiveRegex = /^archive\/(.+)(\.zip|\.tar\.gz)/;
12-
const releaseDownloadRegex = /^releases\/download\/([^/]+)\/(.+)/;
13-
const dependentsRegex = /^network\/dependents\/?$/;
14-
const dependenciesRegex = /^network\/dependencies\/?$/;
15-
const wikiRegex = /^wiki\/(.+)$/;
5+
const patchDiffRegex = /[.](patch|diff)$/;
6+
const releaseRegex = /^releases[/]tag[/]([^/]+)/;
7+
const labelRegex = /^labels[/]([^/]+)/;
8+
const compareRegex = /^compare[/]([^/]+)/;
9+
const pullRegex = /^pull[/](?<pull>\d+)(?:[/](?<pullPage>[^/]+))?(?:[/](?<pullPartialStart>[\da-f]{40})[.][.](?<pullPartialEnd>[\da-f]{40}))?$/;
10+
const issueRegex = /^issues[/](\d+)$/;
11+
const commitRegex = /^commit[/]([\da-f]{40})$/;
12+
const releaseArchiveRegex = /^archive[/](.+)([.]zip|[.]tar[.]gz)/;
13+
const releaseDownloadRegex = /^releases[/]download[/]([^/]+)[/](.+)/;
14+
const dependentsRegex = /^network[/]dependents[/]?$/;
15+
const dependenciesRegex = /^network[/]dependencies[/]?$/;
16+
const wikiRegex = /^wiki[/](.+)$/;
1617

1718
/** @type {(searchParameters: URLSearchParams, pathname: string) => string} */
1819
function pullQueryOut(searchParameters, pathname) {
@@ -41,7 +42,7 @@ function styleRevision(revision) {
4142
}
4243

4344
revision = revision.replace(patchDiffRegex, '');
44-
if (/^[\da-f]{40}$/.test(revision)) {
45+
if (/^[0-9a-f]{40}$/.test(revision)) {
4546
revision = revision.slice(0, 7);
4647
}
4748

@@ -161,10 +162,10 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
161162
if (isReserved || pathname === '/' || (!isLocal && !isRaw && !isRedirection)) {
162163
const cleanHref = [
163164
origin
164-
.replace(/^https:\/\//, '')
165-
.replace(/^www\./, ''),
165+
.replace(/^https:[/][/]/, '')
166+
.replace(/^www[.]/, ''),
166167
pathname
167-
.replace(/\/$/, ''),
168+
.replace(/[/]$/, ''),
168169
];
169170

170171
if (['issues', 'pulls'].includes(user) && !repo) {
@@ -275,7 +276,7 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
275276
}
276277

277278
// Drop leading and trailing slash of relative path
278-
return pathname.replaceAll(/^\/|\/$/g, '') + url.search + hash + query;
279+
return pathname.replaceAll(/^[/]|[/]$/g, '') + url.search + hash + query;
279280
}
280281
/* eslint-enable complexity */
281282

0 commit comments

Comments
 (0)