Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 2e1b2a5

Browse files
mmaleckiothiym23
authored andcommitted
decode the package name from the request URL
Present the decoded package name in the error message if present. Fixes npm/registry-frontdoor#116. Fixes npm/npme-auth-userapi#16.
1 parent dd40299 commit 2e1b2a5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function requestDone (method, where, cb) {
232232
var name
233233
if (!w.match(/^-/)) {
234234
w = w.split('/')
235-
name = w[w.indexOf('_rewrite') + 1]
235+
name = decodeURIComponent(w[w.indexOf('_rewrite') + 1])
236236
}
237237

238238
if (!parsed.error) {
@@ -245,7 +245,7 @@ function requestDone (method, where, cb) {
245245
er = new Error('404 Not Found: ' + name)
246246
} else {
247247
er = new Error(
248-
parsed.error + ' ' + (parsed.reason || '') + ': ' + w
248+
parsed.error + ' ' + (parsed.reason || '') + ': ' + (name || w)
249249
)
250250
}
251251
if (name) er.pkgid = name

test/request.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test('request call contract', function (t) {
8181
})
8282

8383
test('run request through its paces', function (t) {
84-
t.plan(27)
84+
t.plan(28)
8585

8686
server.expect('/request-defaults', function (req, res) {
8787
t.equal(req.method, 'GET', 'uses GET by default')
@@ -166,6 +166,13 @@ test('run request through its paces', function (t) {
166166
}))
167167
})
168168

169+
server.expect('GET', '/@scoped%2Fpackage-failing', function (req, res) {
170+
req.pipe(concat(function () {
171+
res.statusCode = 402
172+
res.json({ error: 'payment required' })
173+
}))
174+
})
175+
169176
var defaults = {}
170177
client.request(
171178
common.registry + '/request-defaults',
@@ -249,4 +256,8 @@ test('run request through its paces', function (t) {
249256
client.request(common.registry + '/body-error-object', defaults, function (er) {
250257
t.ifError(er, 'call worked')
251258
})
259+
260+
client.request(common.registry + '/@scoped%2Fpackage-failing', defaults, function (er) {
261+
t.equals(er.message, 'payment required : @scoped/package-failing')
262+
})
252263
})

0 commit comments

Comments
 (0)