I'm writing a test and for such I need to create a Response object to mock the result to an HTTP call.
It turns out the JSON I'm using as base for the response body contains a "bullet" character (•).
When creating the Response manually through new Response("[...]•[...]", 200) I get this error:
Invalid argument(s): String contains invalid characters.
When the production code access the real webservice and receive the response containing the very same character everything goes fine (maybe because the body is filled from a stream, unlike my case where I do it through a String).
Ensure that the encoding is UTF8. I think that should fix your issue.
@gdomingues What version of http are you using?
In master this will fail with the error he's describing but by default it will encode in UTF8 so I'm assuming 0.11.
var response = new http.Response('http://foo.com', 200, body: '[...]•[...]', encoding: ASCII);
@nex3 This is the version I'm using: "^0.11.3+14"
There's no argument for setting the encoding directly on Response constructor, therefore I assume it was added on version 12 right?
I tried setting the header like this:
new Response(jsonString, 200, headers: {
"content-type": "application/json; charset=utf-8",
})
Now the problem is not the bullet character anymore, but the # char, despite it being present on UTF-8 character set list:

Can you provide a standalone Dart script that reproduces this problem?
Most helpful comment
Ensure that the encoding is UTF8. I think that should fix your issue.