Skip to content

Commit

Permalink
satisfying linter, removed ability to instance the generic parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sdellysse committed Apr 17, 2020
1 parent 8adc464 commit 9496e43
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
3 changes: 0 additions & 3 deletions index.js
Expand Up @@ -161,9 +161,6 @@ function loadParser (parserName) {
case 'urlencoded':
parser = require('./lib/types/urlencoded')
break
case 'generic':
parser = require('./lib/generic-parser')
break
}

// store to prevent invoking require()
Expand Down
12 changes: 6 additions & 6 deletions lib/types/json.js
Expand Up @@ -44,7 +44,7 @@ var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*(.)/ // eslint-disable-line no-cont
* @public
*/

function json(options) {
function json (options) {
var opts = options || {}

var reviver = opts.reviver
Expand All @@ -55,11 +55,11 @@ function json(options) {
return genericParser(assign({}, opts, {
type: type,

charset: function validateCharset(charset) {
charset: function validateCharset (charset) {
return charset.substr(0, 4) === 'utf-'
},

parse: function parse(buf) {
parse: function parse (buf) {
if (buf.length === 0) {
// special-case empty json body, as it's a common client-side mistake
// TODO: maybe make this configurable or part of "strict" option
Expand Down Expand Up @@ -97,7 +97,7 @@ function json(options) {
* @private
*/

function createStrictSyntaxError(parser, reviver, str, char) {
function createStrictSyntaxError (parser, reviver, str, char) {
var index = str.indexOf(char)
var partial = str.substring(0, index) + '#'

Expand All @@ -119,7 +119,7 @@ function createStrictSyntaxError(parser, reviver, str, char) {
* @private
*/

function firstchar(str) {
function firstchar (str) {
return FIRST_CHAR_REGEXP.exec(str)[1]
}

Expand All @@ -131,7 +131,7 @@ function firstchar(str) {
* @return {SyntaxError}
*/

function normalizeJsonSyntaxError(error, obj) {
function normalizeJsonSyntaxError (error, obj) {
var keys = Object.getOwnPropertyNames(error)

for (var i = 0; i < keys.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/types/urlencoded.js
Expand Up @@ -51,8 +51,8 @@ function urlencoded (options) {

var queryparse = opts.parser || (
extended
? extendedparser(opts)
: simpleparser(opts)
? extendedparser(opts)
: simpleparser(opts)
)

return genericParser(assign({}, opts, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -50,4 +50,4 @@
"test-cov": "nyc --reporter=html --reporter=text npm test",
"test-travis": "nyc --reporter=text npm test"
}
}
}
8 changes: 4 additions & 4 deletions test/json.js
Expand Up @@ -75,10 +75,10 @@ describe('bodyParser.json()', function () {
return { foo: 'bar' }
}
}))
.post('/')
.set('Content-Type', 'application/json')
.send('{"str":')
.expect(200, '{"foo":"bar"}', done)
.post('/')
.set('Content-Type', 'application/json')
.send('{"str":')
.expect(200, '{"foo":"bar"}', done)
})

describe('when JSON is invalid', function () {
Expand Down
8 changes: 4 additions & 4 deletions test/urlencoded.js
Expand Up @@ -23,10 +23,10 @@ describe('bodyParser.urlencoded()', function () {
request(createServer({
parser: function (input) { return input.toUpperCase() }
}))
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send('user=tobi')
.expect(200, '"USER=TOBI"', done)
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send('user=tobi')
.expect(200, '"USER=TOBI"', done)
})

it('should 400 when invalid content-length', function (done) {
Expand Down

0 comments on commit 9496e43

Please sign in to comment.