{ "id": "171355", "key": "TIMOB-25921", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2018-03-20T00:13:18.000+0000", "priority": null, "labels": [], "versions": [], "issuelinks": [], "assignee": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2018-03-31T23:35:19.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [], "description": "Ti.Codec.encodeString with Ti.Codec.CHARSET_ISO_LATIN_1 does not handle text containing single or double curly quotes. When a string containing curly quotes is encoded, then decoded, an string containing zero bytes is returned.\r\n\r\nThis happens in the most recent 7.1 version of Titanium SDK. I believe it happens in earlier versions as well.\r\n\r\nThe issue only happens on iOS. The same code works fine on Android.", "attachment": [ { "id": "64982", "filename": "encode bug.txt", "author": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "created": "2018-03-22T15:25:20.000+0000", "size": 2514, "mimeType": "text/plain" } ], "flagged": false, "summary": "Ti.Codec.encodeString does not handle curly quotes", "creator": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "subtasks": [], "reporter": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "environment": null, "comment": { "comments": [ { "id": "435746", "author": { "name": "mrahman", "key": "mrahman", "displayName": "Mostafizur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hello [~dethier1958], Thanks for sharing with us. Please provide a full sample test code that regenerates the issue. Better to provide a sample app as an attachment here. We will test the issue in our environment. Also, provide the environment details you are testing on. Thanks.", "updateAuthor": { "name": "mrahman", "key": "mrahman", "displayName": "Mostafizur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "created": "2018-03-20T04:25:59.000+0000", "updated": "2018-03-20T04:25:59.000+0000" }, { "id": "435764", "author": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "body": "Upon taking a closer look, I noticed that this is with smart quotes, which iOS substitutes for normal quotes in edit fields. For my app, I will probably just do some sort of replacement to work around this issue. And perhaps this is an Apple issue.\r\n\r\nHere is some sample code that reproduces the problem:\r\n\r\n\r\n{code}\r\n//\tWhen a string contains smart quotes (single or double), then encode\r\n//\tand decode will not work. The string pulled out of the buffer by decode\r\n//\twill be blank.\r\n\r\n\r\nvar buffer = Ti.createBuffer({ length: 46800 });\r\nvar text = 'This “has” Quotes�\\0';\r\n\r\nvar str;\r\n\r\n\r\nTi.API.info('text = ' + text);\r\n\r\n\r\nTi.Codec.encodeString({\r\n\tcharset:\t\tTi.Codec.CHARSET_ISO_LATIN_1,\r\n\tsource:\t\ttext,\r\n\tdest:\t\tbuffer,\r\n\tdestPosition:\t15600\r\n\t});\r\n\r\nstr = Ti.Codec.decodeString({\r\n\tcharset:\t\tTi.Codec.CHARSET_ISO_LATIN_1,\r\n\tsource:\t\tbuffer,\r\n\tposition:\t\t15600,\r\n\tlength:\t\t48\r\n\t});\r\n\r\n\r\nTi.API.info('str = ' + str);\r\n{code}\r\n\r\nJust create a new mobile project for iPhone and iPad and replace the code in app.js with this. The output on the console will look like this:\r\n\r\n{code}\r\n[INFO] : Launching iOS Simulator\r\n[INFO] : Codec Bug/1.0 (7.1.0.df92fbf)\r\n[INFO] : text = This “has” Quotes��\r\n[INFO] : str = ������������������������������������������������\r\n{code}\r\n\r\nThis happens for smart quotes, not regular quotes, which is interesting. It only seems to happen for the CHARSET_ISO_LATIN_1 encoding.", "updateAuthor": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-03-20T15:54:18.000+0000", "updated": "2018-03-21T10:49:47.000+0000" }, { "id": "435825", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello, I wasn't able to reproduce the issue. I don't see any quotes in the \"str =\". See my log. Thanks.\r\n\r\n[INFO] Launching iOS Simulator\r\n-- Start simulator log -------------------------------------------------------\r\n[INFO] sampro/1.0 (7.1.0.df92fbf)\r\n[INFO] text = This “has” Quotes�\r\n[INFO] str = \r\n", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2018-03-21T22:17:44.000+0000", "updated": "2018-03-21T22:17:44.000+0000" }, { "id": "435828", "author": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "body": "That's the bug. The variable text is set to a string containing smart quotes. That string is encoded into a buffer, then that same position in the buffer is read out. The variable str is what comes out of decode. It should be identical to text. But it isn't. It comes out blank if there are smart quotes (single or double) in text. Remove the smart quotes around has in text and it comes out the same.", "updateAuthor": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "created": "2018-03-21T22:54:28.000+0000", "updated": "2018-03-21T22:54:28.000+0000" }, { "id": "435849", "author": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "body": "I attached a better example that demonstrates what is happening. \r\n\r\nThere are two versions of the example. One encodes a string that has no curly quotes. The bytes are then pulled from those positions of the buffer into an array. Then the buffer is decoded into a string. This version works fine. The string is copied into the buffer. When you pull individual bytes from the buffer, you get the bytes for the characters in the string.\r\n\r\nThe second version of the example has a string containing curly quotes around the work has. After encoding this string into the buffer, the bytes pulled from the buffer are all zeroes. And the string decoded from the buffer is a string of zero bytes. The issue seems to be that encodeString does not copy the string into the buffer when the string contains curly quotes.\r\n\r\nI hope this helps clarify the issue.", "updateAuthor": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "created": "2018-03-22T15:29:16.000+0000", "updated": "2018-03-22T15:29:16.000+0000" }, { "id": "436001", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello [~dethier1958], Can you try a different charset like CHARSET_UTF8 ? We think the \"special\" quotes aren't part of the LATIN charset. Let us know the result. Thanks.", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2018-03-28T00:44:02.000+0000", "updated": "2018-03-28T00:44:02.000+0000" }, { "id": "436002", "author": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "body": "I had tried UTF-8 and that worked. I tried ASCII and that worked, but that causes other problems with various accented characters. I believe you are correct.\r\n\r\nI did discover that Apple recently made a change in the default text field behavior to automatically convert quotes to curly quotes. I changed my edit fields to use ASCII keyboard and that prevents that, which allows me to avoid the issue.\r\n\r\nPerhaps you could add more encoding options (Apple provides more constants for various encodings). That would provide other options to get around the issue in the future. See https://developer.apple.com/documentation/foundation/string.encoding", "updateAuthor": { "name": "dethier1958", "key": "dethier1958", "displayName": "Daniel Ethier", "active": true, "timeZone": "America/Chicago" }, "created": "2018-03-28T00:52:43.000+0000", "updated": "2018-03-28T00:52:43.000+0000" }, { "id": "436062", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello [~dethier1958], Thanks for your suggestion. Our engineers will look into that. ", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2018-03-29T00:35:28.000+0000", "updated": "2018-03-29T00:35:28.000+0000" } ], "maxResults": 12, "total": 12, "startAt": 0 } } }