Skip to content

Response constructor doesn't accept U+2022 inside body (says invalid character) #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gdomingues opened this issue Sep 19, 2017 · 5 comments
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@gdomingues
Copy link

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

@donny-dont
Copy link

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

@nex3
Copy link
Member

nex3 commented Sep 20, 2017

@gdomingues What version of http are you using?

@nex3 nex3 added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) needs info labels Sep 20, 2017
@donny-dont
Copy link

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

@gdomingues
Copy link
Author

@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

@nex3
Copy link
Member

nex3 commented Sep 21, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants