-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fixed missing payload encoding conversion (from UTF-8 to UTF-16) #56
Conversation
Hey @djuelg Thanks for the PR. A few points:
|
var request = http.Request('POST', Uri.parse(loginAPIURL)); | ||
request.headers['Content-Type'] = "application/json; charset=utf-8"; | ||
var body = {"userId": "supertokens-flutter-tests", "payload": { | ||
"name": "\xc3\xb6\xc3\xa4\xc3\xbc\x2d\xc3\xa1\xc3\xa0\xc3\xa2" // UTF-8 encoded öäü-áàâ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think the login enpoint here actually uses the payload
prop in the reuqest to add to the access token payload of the session. So that probably needs to be modified as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that's a mixup with /login-2.18
, where the request payload gets passed to the token. Would it be fine to run the test against /login-2.18
? Or should I rather adapt the /login
node-function?
In the second case, I guess I would need to pass the payload like so: Session.createNewSession(req, res, userId, accessTokenPayload: payloadFromRequest);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct. You should adapt the login API and pass in the payloadFromRequest
to the createNewSession function in case the request body has this prop
Yeah no, you got me there. I kind of had hopes that some pipeline might run the tests automatically, so that I can avoid setting up the whole testing-environment for such a small change. I can look into setting it up in a couple of days.
Will do with next commit, that will also adress the code comments. Have a nice day :) |
@djuelg did you get around to running the test? |
Summary of change
Dart Strings always have a UTF-16 encoding. We receive token payloads encoded in UTF-8 from the Supertokens backend. Due to a known issue with jsonDecode in Flutter, the JSON contents are not converted from UTF-8 to UTF-16 encoding. This presents challenges, particularly with strings containing special characters such as ö, ä, or ü.
In the proposed update, before performing JSON decoding, we implement UTF-8 decoding using utf8.decode. This ensures that the resulting data structure is a properly encoded Map<String, dynamic>, where special characters are represented correctly.
Related issues
Test Plan