🐛 FIX: path url maybe encode (#1729)

This commit is contained in:
fengmk2
2022-04-28 09:48:27 +08:00
committed by GitHub
parent 6c12a040a5
commit f8bcca1ea0
2 changed files with 15 additions and 1 deletions

View File

@@ -23,10 +23,14 @@ module.exports = function* notFound(next) {
} }
// package not found // package not found
m = /^\/package\/([\w\-\_\.]+)\/?$/.exec(this.url); m = /^\/package\/([\w\-\_\.]+)\/?$/.exec(this.path);
if (!m) { if (!m) {
// scoped packages // scoped packages
m = /^\/package\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(this.path); 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 name = null;
var title = '404: Page Not Found'; var title = '404: Page Not Found';

View File

@@ -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); .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 => { it('should get 404 show sync button on non-scoped package', done => {
mm(config, 'syncModel', 'all'); mm(config, 'syncModel', 'all');
request(app) request(app)