Http: Response constructor doesn't accept U+2022 inside body (says `invalid character`)

Created on 19 Sep 2017  Â·  5Comments  Â·  Source: dart-lang/http

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).

need-info type-bug

Most helpful comment

Ensure that the encoding is UTF8. I think that should fix your issue.

All 5 comments

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:

screen shot 2017-09-21 at 08 48 23

Can you provide a standalone Dart script that reproduces this problem?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chris1234567899 picture Chris1234567899  Â·  6Comments

Jonas-Sander picture Jonas-Sander  Â·  6Comments

jet10000 picture jet10000  Â·  5Comments

Buckstabue picture Buckstabue  Â·  7Comments

Blykam picture Blykam  Â·  6Comments