JSDOM accepts a buffer but doesn't allow to set a content type encoding and defaults to windows-1252
See original GitHub issueBasic 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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, the
contentType
option is not the same as a content-type header. You can’t supply headers with aBuffer
.But, maybe we should treat it similarly, instead of only treating it as an XML vs. HTML mode switch. Hmm.
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.