Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe('bodyParser.json()', function () {
.post('/')
.set('Content-Type', 'application/json')
.send('true')
.expect(400, '[entity.parse.failed] ' + parseError('#rue').replace('#', 't'), done)
.expect(400, '[entity.parse.failed] ' + parseError('#rue', true).replace('#', 't'), done)
})
})

Expand Down Expand Up @@ -273,15 +273,15 @@ describe('bodyParser.json()', function () {
.post('/')
.set('Content-Type', 'application/json')
.send('true')
.expect(400, '[entity.parse.failed] ' + parseError('#rue').replace('#', 't'), done)
.expect(400, '[entity.parse.failed] ' + parseError('#rue', true).replace('#', 't'), done)
})

it('should not parse primitives with leading whitespaces', function (done) {
request(this.server)
.post('/')
.set('Content-Type', 'application/json')
.send(' true')
.expect(400, '[entity.parse.failed] ' + parseError(' #rue').replace('#', 't'), done)
.expect(400, '[entity.parse.failed] ' + parseError(' #rue', true).replace('#', 't'), done)
})

it('should allow leading whitespaces in JSON', function (done) {
Expand All @@ -299,7 +299,7 @@ describe('bodyParser.json()', function () {
.set('X-Error-Property', 'stack')
.send('true')
.expect(400)
.expect(shouldContainInBody(parseError('#rue').replace('#', 't')))
.expect(shouldContainInBody(parseError('#rue', true).replace('#', 't')))
.end(done)
})
})
Expand Down Expand Up @@ -732,9 +732,9 @@ function createServer (opts) {
})
}

function parseError (str) {
function parseError (str, first = false) {
try {
JSON.parse(str); throw new SyntaxError('strict violation')
JSON.parse(first ? /^(\s*.)/.exec(str)[1] : str); throw new SyntaxError('strict violation')
} catch (e) {
return e.message
}
Expand Down