question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSDOM accepts a buffer but doesn't allow to set a content type encoding and defaults to windows-1252

See original GitHub issue

Basic info:

  • **Node.js version: 8.10
  • **jsdom version: 13.1

Minimal reproduction case

const { JSDOM } = require("jsdom");
const dom = new JSDOM(buffer, {
  contentType: res.headers['content-type'], // Doesn't use the charset from content-type
  encoding: 'UTF-8' // Doesn't use the passed encoding
});

It should either automatically extract charset from options.contentType, or it should allow to pass options.encoding.

Internally it’s using transportLayerEncodingLabelHiddenOption to pass the encoding, therefore fromURL method works correctly.

https://github.com/jsdom/jsdom/blob/master/lib/api.js#L33

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
domeniccommented, Jan 24, 2019

Well, the contentType option is not the same as a content-type header. You can’t supply headers with a Buffer.

But, maybe we should treat it similarly, instead of only treating it as an XML vs. HTML mode switch. Hmm.

0reactions
csmrcommented, Feb 21, 2019

Am I understanding correctly: the html5-documents meta-tags Content-Type with charset=UTF-8 is ignored when “handling a buffer”?

It seems to me, that this will destroy your document unless it is encoded with the default charset.

Also, please note that a browser will look for the meta http-equiv=“Content-Type” for encoding information , and if it is found, re-parse the document with the specified encoding.

With that, it seems to me this is not a desired feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contributing to JSDOM - Charper Bonaroo
I let them run, but I assume my change is fine. Removing request from lib/jsdom/browser/resources/resource-loader.js. Now that the test ...
Read more >
urlencoding form data with windows-1252 charset in node.js
i tried another package "Restler", which allows encoding to be set but it throws exception saying invalid charset when i specify windows-1252 ( ......
Read more >
Iconv to utf 8 - Caritas Castellaneta
Iconv plugin provides a solution for both scenarios. Should be converted to cess. It converts between many available character encodings.
Read more >
Changelog.md - jest-environment-jsdom-fourteen - GitLab
Fixed XML documents to default to UTF-8, not windows-1252 like HTML ... Fixed XMLHttpRequest to correctly set the User-Agent header, and set ......
Read more >
How do I convert a character code in one coding system ...
I don't know how I missed this in the manual, but the function I was looking for is decode-char , e.g. (decode-char 'cp1252...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found