fix: Initialize Content-Type as empty string if not present (#359)

pull/358/head^2
John Holdun 5 years ago committed by Adam Pash
parent da9a836eab
commit 437f50a5c8

@ -40,7 +40,7 @@ const Resource = {
},
generateDoc({ body: content, response }) {
const { 'content-type': contentType } = response.headers;
const { 'content-type': contentType = '' } = response.headers;
// TODO: Implement is_text function from
// https://github.com/ReadabilityHoldings/readability/blob/8dc89613241d04741ebd42fa9fa7df1b1d746303/readability/utils/text.py#L57

@ -97,6 +97,25 @@ describe('Resource', () => {
}, /content does not appear to be text/i);
});
it('throws an error if the response has no Content-Type header', () => {
const response = {
headers: {},
};
const body = '';
// This assertion is more elaborate than the others to be sure that we're
// throwing an `Error` and not raising a runtime exception.
assert.throws(
() => {
Resource.generateDoc({ body, response });
},
err => (
(err instanceof Error) &&
/content does not appear to be text/i.test(err)
)
);
});
it('throws an error if the content has no children', () => {
// jquery's parser won't work this way, and this is
// an outside case

Loading…
Cancel
Save