|
1 | 1 | /* global document */ |
| 2 | +/* eslint-disable unicorn/better-regex */ |
2 | 3 | import reservedNames from 'github-reserved-names/reserved-names.json' with { type: 'json' }; |
3 | 4 |
|
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[/](.+)$/; |
16 | 17 |
|
17 | 18 | /** @type {(searchParameters: URLSearchParams, pathname: string) => string} */ |
18 | 19 | function pullQueryOut(searchParameters, pathname) { |
@@ -41,7 +42,7 @@ function styleRevision(revision) { |
41 | 42 | } |
42 | 43 |
|
43 | 44 | revision = revision.replace(patchDiffRegex, ''); |
44 | | - if (/^[\da-f]{40}$/.test(revision)) { |
| 45 | + if (/^[0-9a-f]{40}$/.test(revision)) { |
45 | 46 | revision = revision.slice(0, 7); |
46 | 47 | } |
47 | 48 |
|
@@ -161,10 +162,10 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') { |
161 | 162 | if (isReserved || pathname === '/' || (!isLocal && !isRaw && !isRedirection)) { |
162 | 163 | const cleanHref = [ |
163 | 164 | origin |
164 | | - .replace(/^https:\/\//, '') |
165 | | - .replace(/^www\./, ''), |
| 165 | + .replace(/^https:[/][/]/, '') |
| 166 | + .replace(/^www[.]/, ''), |
166 | 167 | pathname |
167 | | - .replace(/\/$/, ''), |
| 168 | + .replace(/[/]$/, ''), |
168 | 169 | ]; |
169 | 170 |
|
170 | 171 | if (['issues', 'pulls'].includes(user) && !repo) { |
@@ -275,7 +276,7 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') { |
275 | 276 | } |
276 | 277 |
|
277 | 278 | // 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; |
279 | 280 | } |
280 | 281 | /* eslint-enable complexity */ |
281 | 282 |
|
|
0 commit comments