Skip to content

Commit 9d9c492

Browse files
committed
Added support for parsing '+xml' types
1 parent 65f3aba commit 9d9c492

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

.jshintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"node": true,
3+
"mocha": true,
4+
"esnext": true,
5+
"bitwise": true,
6+
"curly": true,
7+
"eqeqeq": true,
8+
"immed": true,
9+
"indent": 2,
10+
"latedef": true,
11+
"newcap": false,
12+
"noarg": true,
13+
"quotmark": "single",
14+
"regexp": true,
15+
"undef": true,
16+
"unused": true,
17+
"strict": true,
18+
"trailing": true,
19+
"smarttabs": true
20+
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(bodyParser) {
1010
return;
1111
}
1212

13-
var xmlTypes = ['application/xml', 'text/xml'];
13+
var xmlTypes = ['*/xml', '+xml'];
1414

1515
function xml(options) {
1616
options = options || {};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
},
2828
"devDependencies": {
2929
"body-parser": "^1.14.2",
30-
"chai": "^3.4.1",
3130
"express": "^4.13.3",
3231
"mocha": "^2.3.4",
3332
"supertest": "^1.1.0"

test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
var express = require('express'),
44
request = require('supertest'),
5-
bodyParser = require('body-parser'),
6-
expect = require('chai').expect;
5+
bodyParser = require('body-parser');
76

87
// Add xml parsing to bodyParser.
98
// In real-life you'd `require('body-parser-xml')`.
@@ -14,6 +13,7 @@ describe('XML Body Parser', function() {
1413

1514
var createServer = function(options) {
1615
app = express();
16+
app.set('env', 'test');
1717
app.use(bodyParser.xml(options));
1818
app.post('/', function(req, res) {
1919
res.status(200).send({ parsed: req.body });
@@ -44,6 +44,16 @@ describe('XML Body Parser', function() {
4444
.expect(200, { parsed: { customer: { name: ['Bob'] } } }, done);
4545
});
4646

47+
it('should parse a body with content-type application/rss+xml', function(done) {
48+
createServer();
49+
50+
request(app)
51+
.post('/')
52+
.set('Content-Type', 'application/rss+xml')
53+
.send('<customer><name>Bob</name></customer>')
54+
.expect(200, { parsed: { customer: { name: ['Bob'] } } }, done);
55+
});
56+
4757
it('should accept xmlParseOptions', function(done) {
4858
createServer({
4959
xmlParseOptions: {

0 commit comments

Comments
 (0)