question

court avatar image
court asked

Node SDK: Content-Length and UTF8

Hi -

It looks like the Node SDK doesn't handle long utf8 characters correctly when it's posting to the server. The https module ends up encoding into utf8, but the Content-Length was set using the string's length. When including emoji in the request (because who doesn't want an airplane in their username!), the content length will be too short, and the server will report that the string was unterminated. To replicate, using the Admin SDK. You'll need to put some emoji characters in the DisplayName -- the forum software was giving me an error when attempting to create a post with the real request.

PlayFabAdmin.UpdateUserTitleDisplayName({

  PlayFabId: "85A8979D97D576B8",       

  DisplayName: "emoji-characters-here"})

You'll get the following error:

{"code":400,"status":"BadRequest","error":"InvalidRequest","errorCode":1071,"errorMessage":"Invalid JSON in request","errorHash":"d863310ed6e31a73160eaa8939e9c3c9","errorDetails":{"ValidationError":["Unterminated string passed in. (62): {\"PlayFabId\":\"85A8979D97D576B8\",\"DisplayName\":\"dbeets"]}} 

The correction is very easy: in the MakeRequest function, change the stringify from

    var requestBody = JSON.stringify(request);

to

    var requestBody = Buffer.from(JSON.stringify(request), 'utf8');

Then everything will work correctly. I created a pull request on GitHub showing this change: https://github.com/PlayFab/NodeSDK/pull/88.

Cheers

-Courtland

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
1807605288 avatar image
1807605288 answered

This is awesome, thank you for finding it and fixing it for us.

I will accept the pull request tomorrow, and port it over to our SdkGenerator.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.