Skip to content

Commit

Permalink
fix(jsonBodyParser): fix percent sign causing server fail (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtkowiak authored and DonutEspresso committed Feb 5, 2018
1 parent 74e0cf5 commit bde8fda
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/plugins/jsonBodyParser.js
Expand Up @@ -38,7 +38,10 @@ function jsonBodyParser(options) {
params = JSON.parse(req.body, opts.reviver);
} catch (e) {
return next(
new errors.InvalidContentError('Invalid JSON: ' + e.message)
new errors.InvalidContentError(
'%s',
'Invalid JSON: ' + e.message
)
);
}

Expand Down
29 changes: 29 additions & 0 deletions test/plugins/jsonBodyParser.test.js
Expand Up @@ -464,4 +464,33 @@ describe('JSON body parser', function() {

CLIENT.post('/body/foo', payload, done);
});

it('should not throw uncaught "too few args to sprintf"', function(done) {
// https://github.com/restify/node-restify/issues/1411
SERVER.use(restify.plugins.bodyParser());

SERVER.post('/', function(req, res, next) {
res.send();
next();
});

var opts = {
hostname: '127.0.0.1',
port: PORT,
path: '/',
method: 'POST',
agent: false,
headers: {
accept: 'application/json',
'content-type': 'application/json'
}
};
var client = http.request(opts, function(res) {
assert.equal(res.statusCode, 400);
res.once('end', done);
res.resume();
});
client.write('{"malformedJsonWithPercentSign":30%}');
client.end();
});
});

0 comments on commit bde8fda

Please sign in to comment.