Skip to content

Commit 437f50a

Browse files
johnholdunadampash
authored andcommitted
fix: Initialize Content-Type as empty string if not present (#359)
1 parent da9a836 commit 437f50a

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/resource/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const Resource = {
4040
},
4141

4242
generateDoc({ body: content, response }) {
43-
const { 'content-type': contentType } = response.headers;
43+
const { 'content-type': contentType = '' } = response.headers;
4444

4545
// TODO: Implement is_text function from
4646
// https://github.com/ReadabilityHoldings/readability/blob/8dc89613241d04741ebd42fa9fa7df1b1d746303/readability/utils/text.py#L57

src/resource/index.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ describe('Resource', () => {
9797
}, /content does not appear to be text/i);
9898
});
9999

100+
it('throws an error if the response has no Content-Type header', () => {
101+
const response = {
102+
headers: {},
103+
};
104+
const body = '';
105+
106+
// This assertion is more elaborate than the others to be sure that we're
107+
// throwing an `Error` and not raising a runtime exception.
108+
assert.throws(
109+
() => {
110+
Resource.generateDoc({ body, response });
111+
},
112+
err => (
113+
(err instanceof Error) &&
114+
/content does not appear to be text/i.test(err)
115+
)
116+
);
117+
});
118+
100119
it('throws an error if the content has no children', () => {
101120
// jquery's parser won't work this way, and this is
102121
// an outside case

0 commit comments

Comments
 (0)