Skip to content

Remove type checking on type check option #13

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Controls the maximum request body size. If this is a number, then the value spec

#### type

The expected `Content-Type` of the XML request to be parsed. Overrides the default content types, can be a String or Array of Strings.
The type option is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like xml), a mime type (like application/xml), or a mime type with a wildcard (like */* or */xml). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value. Defaults to `['*/xml', '+xml']`.

#### verify

Expand Down
3 changes: 0 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ module.exports = function(bodyParser) {
options = options || {};

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

var textParser = bodyParser.text(options);
return function xmlParser(req, res, next) {
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