Skip to content

Commit 6d664b2

Browse files
committed
Fix: XML body-parser in testbench server is giving error
1 parent 2abead8 commit 6d664b2

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

packages/bruno-tests/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const saveRawBody = (req, res, buf) => {
2929
app.use(bodyParser.json({ verify: saveRawBody }));
3030
app.use(bodyParser.urlencoded({ extended: true, verify: saveRawBody }));
3131
app.use(bodyParser.text({ verify: saveRawBody }));
32-
app.use(xmlParser());
3332
app.use(express.raw({ type: '*/*', limit: '100mb', verify: saveRawBody }));
33+
app.use(xmlParser());
3434

3535
formDataParser.init(app, express);
3636

packages/bruno-tests/src/utils/xmlParser.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,18 @@ const xmlParser = () => {
44
const parser = new XMLParser({
55
ignoreAttributes: false,
66
allowBooleanAttributes: true,
7+
attributeNamePrefix: '',
8+
isArray: (name, jpath, isLeafNode) => isLeafNode,
79
});
810

911
return (req, res, next) => {
1012
if (req.is('application/xml') || req.is('text/xml')) {
11-
let data = '';
12-
req.setEncoding('utf8');
13-
req.on('data', (chunk) => {
14-
data += chunk;
15-
});
16-
req.on('end', () => {
17-
try {
18-
req.body = parser.parse(data);
19-
next();
20-
} catch (err) {
21-
res.status(400).send('Invalid XML');
22-
}
23-
});
13+
try {
14+
req.body = parser.parse(req.rawBody);
15+
next();
16+
} catch (err) {
17+
res.status(400).send('Invalid XML');
18+
}
2419
} else {
2520
next();
2621
}

0 commit comments

Comments
 (0)