Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsonBodyParser): fix percent sign causing server fail (#1411) #1597

Merged
merged 1 commit into from Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});