Skip to content

Commit

Permalink
Add workaround to handle URLs of scoped packages with unencoded /
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka authored and rlidwka committed Jul 11, 2015
1 parent 93245c0 commit fde2321
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/index-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ module.exports = function(config, auth, storage) {
app.use(expressJson5({ strict: false, limit: config.max_body_size || '10mb' }))
app.use(Middleware.anti_loop(config))

// encode / in a scoped package name to be matched as a single parameter in routes
app.use(function(req, res, next) {
if (req.url.indexOf('@') != -1) {
// e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3
req.url = req.url.replace(/^(\/@[^\/%]+)\/(?!$)/, '$1%2F')
}
next()
})

// for "npm whoami"
app.get('/whoami', function(req, res, next) {
if (req.headers.referer === 'whoami') {
Expand Down
9 changes: 9 additions & 0 deletions test/functional/scoped.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ module.exports = function() {
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'})
})
})

it('server2 - nginx workaround', function () {
return server2.request({ uri: '/@test/scoped/1.0.0' })
.status(200)
.then(function (body) {
assert.equal(body.name, '@test/scoped')
assert.equal(body.dist.tarball, 'http://localhost:55552/@test%2fscoped/-/scoped-1.0.0.tgz')
})
})
})
}

0 comments on commit fde2321

Please sign in to comment.