Skip to content

Commit

Permalink
fix: revert html parser, use text directly
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed May 23, 2020
1 parent afecb1a commit 4d931c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 0 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports = function(opts) {
const enableJson = checkEnable(enableTypes, 'json');
const enableText = checkEnable(enableTypes, 'text');
const enableXml = checkEnable(enableTypes, 'xml');
const enableHtml = checkEnable(enableTypes, 'html');

opts.detectJSON = undefined;
opts.onerror = undefined; // eslint-disable-line unicorn/prefer-add-event-listener
Expand All @@ -60,14 +59,10 @@ module.exports = function(opts) {
// default xml types
const xmlTypes = ['text/xml', 'application/xml'];

// default html types
const htmlTypes = ['text/html'];

const jsonOpts = formatOptions(opts, 'json');
const formOpts = formatOptions(opts, 'form');
const textOpts = formatOptions(opts, 'text');
const xmlOpts = formatOptions(opts, 'xml');
const htmlOpts = formatOptions(opts, 'html');

const extendTypes = opts.extendTypes || {};

Expand Down Expand Up @@ -115,10 +110,6 @@ module.exports = function(opts) {
return (await parse.text(ctx, xmlOpts)) || '';
}

if (enableHtml && ctx.request.is(htmlTypes)) {
return (await parse.text(ctx, htmlOpts)) || '';
}

return {};
}
};
Expand Down
8 changes: 6 additions & 2 deletions test/middleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,16 @@ describe('test/middleware.test.js', function() {
});
});

describe('html body', function () {
describe('html body by text parser', function () {
it('should parse html body ok', function (done) {
const app = App({
enableTypes: ['html'],
extendTypes: {
text: ['text/html'],
},
enableTypes: ['text'],
});
app.use(async (ctx) => {
console.log(ctx.request.body);
ctx.headers['content-type'].should.equal('text/html');
ctx.request.body.should.equal('<h1>abc</h1>');
ctx.request.rawBody.should.equal('<h1>abc</h1>');
Expand Down

0 comments on commit 4d931c6

Please sign in to comment.