Merge pull request #5851 from Gargol/issue-5808-error-500-with-illegal-character

Returns 404 page instead of crashing when special chars are used in tag slugs
This commit is contained in:
Hannah Wolfe 2015-09-23 17:25:45 +01:00
commit 09d0d5d26e
2 changed files with 11 additions and 2 deletions

View File

@ -14,6 +14,7 @@ var _ = require('lodash'),
Promise = require('bluebird'),
template = require('../helpers/template'),
routeMatch = require('path-match')(),
safeString = require('../utils/index').safeString,
frontendControllers,
staticPostPermalink = routeMatch('/:slug/:edit?');
@ -160,8 +161,8 @@ function renderChannel(channelOpts) {
filter, filterKey;
// Add the slug if it exists in the route
if (channelOpts.route.indexOf(':slug') !== -1) {
options[channelOpts.name] = req.params.slug;
if (channelOpts.route.indexOf(':slug') !== -1 && req.params.slug) {
options[channelOpts.name] = safeString(req.params.slug);
hasSlug = true;
}

View File

@ -79,6 +79,14 @@ describe('Frontend Routing', function () {
.end(doEnd(done));
});
it('should 404 for unknown tag with invalid characters', function (done) {
request.get('/tag/~$pectacular~/')
.expect('Cache-Control', testUtils.cacheRules['private'])
.expect(404)
.expect(/Page not found/)
.end(doEnd(done));
});
it('should 404 for unknown author', function (done) {
request.get('/author/spectacular/')
.expect('Cache-Control', testUtils.cacheRules['private'])