diff --git a/middleware/web_not_found.js b/middleware/web_not_found.js index e2d1019..013e873 100644 --- a/middleware/web_not_found.js +++ b/middleware/web_not_found.js @@ -23,10 +23,14 @@ module.exports = function* notFound(next) { } // package not found - m = /^\/package\/([\w\-\_\.]+)\/?$/.exec(this.url); + m = /^\/package\/([\w\-\_\.]+)\/?$/.exec(this.path); if (!m) { // scoped packages m = /^\/package\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(this.path); + // maybe encode url: /package/%40foo%2Fawdawda + if (!m && this.path.startsWith('/package/%40')) { + m = /^\/package\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(decodeURIComponent(this.path)); + } } var name = null; var title = '404: Page Not Found'; diff --git a/test/controllers/web/package/show.test.js b/test/controllers/web/package/show.test.js index e405597..bf59a81 100644 --- a/test/controllers/web/package/show.test.js +++ b/test/controllers/web/package/show.test.js @@ -124,6 +124,16 @@ describe('test/controllers/web/package/show.test.js', () => { .expect(/Can not found package match @cnpmtest\/testmodule-repo-short-https-404/, done); }); + it('should get 404 show sync button on scoped package with encode url', done => { + mm(config, 'syncModel', 'all'); + request(app) + .get('/package/%40foo%2Fawdawda') + .expect(404) + .expect('content-type', 'text/html; charset=utf-8') + .expect(/>SYNC<\/a> from official npm registry/) + .expect(/Can not found package match @foo\/awdawda/, done); + }); + it('should get 404 show sync button on non-scoped package', done => { mm(config, 'syncModel', 'all'); request(app)