Skip to content

Commit 05afd0f

Browse files
test(json): add RFC 7159 whitespace edge cases (#653)
- Test all RFC 7159 whitespace characters before valid JSON - Test body with only whitespace characters - Improves coverage of firstchar function edge cases
1 parent 2f27257 commit 05afd0f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/json.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,22 @@ describe('bodyParser.json()', function () {
288288
.expect(200, '{"user":"tobi"}', done)
289289
})
290290

291+
it('should handle all RFC 7159 whitespace characters before JSON', function (done) {
292+
request(this.server)
293+
.post('/')
294+
.set('Content-Type', 'application/json')
295+
.send('\x20\x09\x0a\x0d{ "user": "tobi" }')
296+
.expect(200, '{"user":"tobi"}', done)
297+
})
298+
299+
it('should error on body with only RFC 7159 whitespace characters', function (done) {
300+
request(this.server)
301+
.post('/')
302+
.set('Content-Type', 'application/json')
303+
.send('\x20\x09\x0a\x0d')
304+
.expect(400, '[entity.parse.failed] ' + parseError('\x20\x09\x0a\x0d'), done)
305+
})
306+
291307
it('should include correct message in stack trace', function (done) {
292308
request(this.server)
293309
.post('/')

0 commit comments

Comments
 (0)