Skip to content

Commit d46d052

Browse files
authored
fix: tolerate null bugs URLs (#6798)
Currently, if the bugs URL returned from `package.json`, which is processed through [hosted-git-info](https://github.com/npm/hosted-git-info), is falsy, an error is thrown. However, hosted-git-info may well return a falsy bugs URL. This can happen when there is no bugs URL in the repo, but hosted-git-info tries to infer one, but one cannot be inferred, for example if the repository URL is a SourceHut URL. This is described here: npm/hosted-git-info#213 For this reason, we should tolerate falsy URLs and fall back to whatever is defined in `bugs.js`, in this case being sent to https://www.npmjs.com/package/<packageName>.
1 parent 6ec6ff0 commit d46d052

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/commands/bugs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class Bugs extends PackageUrlCmd {
2121

2222
// try to get it from the repo, if possible
2323
const info = this.hostedFromMani(mani)
24-
if (info) {
25-
return info.bugs()
24+
const infoUrl = info?.bugs()
25+
if (infoUrl) {
26+
return infoUrl
2627
}
2728

2829
// just send them to the website, hopefully that has some info!

test/lib/commands/bugs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const pacote = {
66
return spec === 'nobugs' ? {
77
name: 'nobugs',
88
version: '1.2.3',
9+
} : spec === 'nullbugs' ? {
10+
name: 'nullbugs',
11+
version: '1.2.3',
12+
bugs: null,
913
} : spec === 'bugsurl' ? {
1014
name: 'bugsurl',
1115
version: '1.2.3',
@@ -66,6 +70,7 @@ t.test('open bugs urls & emails', async t => {
6670
const expected = {
6771
'.': 'https://example.com',
6872
nobugs: 'https://www.npmjs.com/package/nobugs',
73+
nullbugs: 'https://www.npmjs.com/package/nullbugs',
6974
'bugsobj-nourl': 'https://www.npmjs.com/package/bugsobj-nourl',
7075
bugsurl: 'https://bugzilla.localhost/bugsurl',
7176
bugsobj: 'https://bugzilla.localhost/bugsobj',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy