I'm using the Google Sheets API to export cells that contain Arabic text to a JSON file. When a cell contains text that has an exclamation mark at the end of a sentence (so on the left side of the text in an RTL cell), it switches positions in the API response and ends up on the right (incorrect) side in my resulting JSON output:
"levelSelect:titleOne": "قاوم الطعام غير الصحي!"
The word order is correct, but I would expect the exclamation mark to be after the third double quote from the left and not before the fourth one. The punctuation mark placement is correct in the original cell in Google Sheets:
So all the Unicode RTL characters are coming back in the original order, but the one non Unicode character (the exclamation mark) has switched places.
I query Google Sheets with a higher level library, but even if I make a direct API request (using the OAuth playground), I get the same output (FWIW, it makes the request with charset=utf-8 in the Content-type header). The order is already wrong before I write the response to a file.
At this point, I am not sure if this is a bug in the Google Sheets API, or there is something fundamental I don't understand about how Arabic text should be handled. There doesn't seem to be a magic 'format this mostly Unicode string with the non Unicode characters in the right place' conversion function.
I am aware that there are copy and paste issues bewteen different sources where this can happen when you paste text with formatting from the clipboard. If I copy the cell with Cmd-C (on a Mac) and then paste it into some places with just Cmd-V, I get the reversed order, and if I use Shift-Cmd-V, I get the correct order for the exclamation mark. It's as if what the API sends gets confused here on what format to send.
