-
-
Notifications
You must be signed in to change notification settings - Fork 969
Closed
Labels
bugSomething does not work as it shouldSomething does not work as it shouldgood for beginnerThis issue is easy to fixThis issue is easy to fix✭ help wanted ✭
Description
Describe the bug
- Node.js version: v14.18.3
- OS & version: OSX 12.1
The encoding
option is not working when combined with responseType: 'json'
.
Actual behavior
I created a minimal repro repo : https://github.com/baptistemarchand/got-encoding-repro/blob/main/index.mjs
const res1 = await got('https://latin1-api.vercel.app/', {
encoding: 'latin1',
responseType: 'json',
})
// Outputs: {data: "?"}
console.log('res1', res1.body)
const res2 = await got('https://latin1-api.vercel.app/', {
encoding: 'latin1',
})
// Outputs: {data: "é"}
console.log('res2', JSON.parse(res2.body))
What it does :
I have a dummy api that returns a JSON with the latin1 encoding : https://latin1-api.vercel.app/.
I call it twice with got
:
- once with
responseType: 'json'
=> the encoding seems to be ignored - once without
responseType: 'json'
and instead doing aJSON.parse
manually => encoding working as expected
Here is the result :
Expected behavior
I expected the result of both console.log to be the same. Like this :
res1 { data: 'é' }
res2 { data: 'é' }
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
Metadata
Metadata
Assignees
Labels
bugSomething does not work as it shouldSomething does not work as it shouldgood for beginnerThis issue is easy to fixThis issue is easy to fix✭ help wanted ✭