Skip to content

Commit f2e3f05

Browse files
authored
Fixes an issue with encoding (#154)
* fix: fixes an issue with encoding on the fetch level
1 parent 9b371e5 commit f2e3f05

6 files changed

Lines changed: 141 additions & 72 deletions

File tree

dist/mercury.js

Lines changed: 126 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mercury.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/check-build.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ if (process.env.CI) {
4343
assert.equal(article.title, result.title);
4444
done();
4545
}).catch((e) => {
46-
console.log('There was an error', e.message); // eslint-disable-line no-console
47-
console.log('e.fileName', e.fileName);
48-
console.log('e.lineNumber', e.lineNumber);
46+
console.log(e.name, e.message); // eslint-disable-line no-console
4947
assert.equal(true, false);
5048
done();
5149
});

src/resource/index.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ describe('Resource', () => {
5050
});
5151

5252
describe('generateDoc({ body, response })', () => {
53+
// Ideally the body would be a buffer, because of potential issues with
54+
// string re-encoding, since these strings are blank, it should be fine
55+
// but this is why iconv is throwing warnings.
5356
it('throws an error if the content is not text', () => {
5457
const response = {
5558
headers: {

src/resource/utils/fetch-resource.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export default async function fetchResource(url, parsedUrl) {
9191
timeout: FETCH_TIMEOUT,
9292
// Accept cookies
9393
jar: true,
94+
// Set to null so the response returns as binary and body as buffer
95+
// https://github.com/request/request#requestoptions-callback
96+
encoding: null,
9497
// Accept and decode gzip
9598
gzip: true,
9699
// Follow any redirect

src/resource/utils/fetch-resource.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ describe('fetchResource(url)', () => {
2121
assert.equal(error, true);
2222
});
2323

24+
it('returns a buffer as its body', async () => {
25+
const url = 'https://www.washingtonpost.com/news/post-nation/wp/2016/11/05/a-vile-and-disgusting-act-officer-accused-of-giving-fecal-sandwich-to-homeless-man-is-fired/';
26+
const result = await fetchResource(url);
27+
28+
assert.equal(typeof result.body, 'object');
29+
});
30+
2431
it('fetches nyt', async () => {
2532
const url = 'http://www.nytimes.com/2016/08/16/upshot/the-state-of-the-clinton-trump-race-is-it-over.html?_r=0';
2633
const { response } = await fetchResource(url);

0 commit comments

Comments
 (0)