Skip to content

Do not convert type-check-function into array #6

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(bodyParser) {
options = options || {};

options.type = options.type || DEFAULT_TYPES;
if(!Array.isArray(options.type)) {
if(typeof options.type !== 'function' && !Array.isArray(options.type)) {
options.type = [options.type];
}

Expand Down
12 changes: 11 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('XML Body Parser', function() {
});

it('should accept xmlParseOptions', function(done) {
createServer({
createServer({
xmlParseOptions: {
normalize: true, // Trim whitespace inside text nodes
normalizeTags: true, // Transform tags to lowercase
Expand Down Expand Up @@ -91,6 +91,16 @@ describe('XML Body Parser', function() {
.expect(200, { parsed: { customer: { name: ['Bob'] } } }, done);
});

it('should accept custom ContentType as function', function(done) {
createServer({
type: function() { return true }
});
request(app)
.post('/')
.send('<customer><name>Bob</name></customer>')
.expect(200, { parsed: { customer: { name: ['Bob'] } } }, done);
});

it('should ignore non-XML', function(done) {
createServer();

Expand Down