Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an issue with encoding #154

Merged
merged 3 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 126 additions & 68 deletions dist/mercury.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/mercury.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions scripts/check-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ if (process.env.CI) {
assert.equal(article.title, result.title);
done();
}).catch((e) => {
console.log('There was an error', e.message); // eslint-disable-line no-console
console.log('e.fileName', e.fileName);
console.log('e.lineNumber', e.lineNumber);
console.log(e.name, e.message); // eslint-disable-line no-console
assert.equal(true, false);
done();
});
Expand Down
3 changes: 3 additions & 0 deletions src/resource/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ describe('Resource', () => {
});

describe('generateDoc({ body, response })', () => {
// Ideally the body would be a buffer, because of potential issues with
// string re-encoding, since these strings are blank, it should be fine
// but this is why iconv is throwing warnings.
it('throws an error if the content is not text', () => {
const response = {
headers: {
Expand Down
3 changes: 3 additions & 0 deletions src/resource/utils/fetch-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export default async function fetchResource(url, parsedUrl) {
timeout: FETCH_TIMEOUT,
// Accept cookies
jar: true,
// Set to null so the response returns as binary and body as buffer
// https://github.com/request/request#requestoptions-callback
encoding: null,
// Accept and decode gzip
gzip: true,
// Follow any redirect
Expand Down
7 changes: 7 additions & 0 deletions src/resource/utils/fetch-resource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ describe('fetchResource(url)', () => {
assert.equal(error, true);
});

it('returns a buffer as its body', async () => {
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/';
const result = await fetchResource(url);

assert.equal(typeof result.body, 'object');
});

it('fetches nyt', async () => {
const url = 'http://www.nytimes.com/2016/08/16/upshot/the-state-of-the-clinton-trump-race-is-it-over.html?_r=0';
const { response } = await fetchResource(url);
Expand Down