{"action":"created","issue":{"url":"https://api.github.com/repos/marcospassos/java-php-serializer/issues/3","repository_url":"https://api.github.com/repos/marcospassos/java-php-serializer","labels_url":"https://api.github.com/repos/marcospassos/java-php-serializer/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/marcospassos/java-php-serializer/issues/3/comments","events_url":"https://api.github.com/repos/marcospassos/java-php-serializer/issues/3/events","html_url":"https://github.com/marcospassos/java-php-serializer/issues/3","id":300812394,"number":3,"title":"Writing multibyte strings","user":{"login":"middlebrain","id":6077447,"avatar_url":"https://avatars1.githubusercontent.com/u/6077447?v=4","gravatar_id":"","url":"https://api.github.com/users/middlebrain","html_url":"https://github.com/middlebrain","followers_url":"https://api.github.com/users/middlebrain/followers","following_url":"https://api.github.com/users/middlebrain/following{/other_user}","gists_url":"https://api.github.com/users/middlebrain/gists{/gist_id}","starred_url":"https://api.github.com/users/middlebrain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/middlebrain/subscriptions","organizations_url":"https://api.github.com/users/middlebrain/orgs","repos_url":"https://api.github.com/users/middlebrain/repos","events_url":"https://api.github.com/users/middlebrain/events{/privacy}","received_events_url":"https://api.github.com/users/middlebrain/received_events","type":"User","site_admin":false},"labels":[{"id":635668311,"url":"https://api.github.com/repos/marcospassos/java-php-serializer/labels/bug","name":"bug","color":"ee0701","default":true},{"id":635668313,"url":"https://api.github.com/repos/marcospassos/java-php-serializer/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-27T22:09:49Z","updated_at":"2018-02-28T03:18:11Z","closed_at":null,"author_association":"NONE","body":"The current implementation of `writeString` and maybe also `writeProperty` and `writeKey` has the problem, that the length `(s:<length>)` of multibyte strings is not written correctly. This results on the PHP side in `unserialize() [function.unserialize]: Error at offset ...`\r\n\r\nUnfortunately, you must give the length of a serialized string in bytes instead of characters. However, the byte count depends on the character encoding.\r\n\r\nWhen testing the serializer with a servlet I didn't immediately notice this, because the standard encoding of the output is ISO-8859-1 (one character is always one byte).  Only when switching to UTF-8 (`response. setCharacterEncoding(\"UTF-8\"`) and using german umlauts the problem came up.\r\n\r\nMy instant fix for UTF-8 looks like this:\r\n\r\nWriter.java:\r\n\r\n```java\r\n...\r\nimport static java.nio.charset.StandardCharsets.UTF_8;\r\n...\r\n    public void writeString(String value)\r\n    {\r\n        setState(state.value());\r\n\r\n        buffer.append(\"s:\");\r\n        buffer.append(value.getBytes(UTF_8).length);\r\n        buffer.append(\":\\\"\");\r\n        buffer.append(value);\r\n        buffer.append(\"\\\";\");\r\n    }\r\n...\r\n```\r\nIt would certainly be better if the desired character encoding could be given to the writer.\r\n\r\nTranslated with www.DeepL.com/Translator."},"comment":{"url":"https://api.github.com/repos/marcospassos/java-php-serializer/issues/comments/369108067","html_url":"https://github.com/marcospassos/java-php-serializer/issues/3#issuecomment-369108067","issue_url":"https://api.github.com/repos/marcospassos/java-php-serializer/issues/3","id":369108067,"user":{"login":"marcospassos","id":943036,"avatar_url":"https://avatars0.githubusercontent.com/u/943036?v=4","gravatar_id":"","url":"https://api.github.com/users/marcospassos","html_url":"https://github.com/marcospassos","followers_url":"https://api.github.com/users/marcospassos/followers","following_url":"https://api.github.com/users/marcospassos/following{/other_user}","gists_url":"https://api.github.com/users/marcospassos/gists{/gist_id}","starred_url":"https://api.github.com/users/marcospassos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcospassos/subscriptions","organizations_url":"https://api.github.com/users/marcospassos/orgs","repos_url":"https://api.github.com/users/marcospassos/repos","events_url":"https://api.github.com/users/marcospassos/events{/privacy}","received_events_url":"https://api.github.com/users/marcospassos/received_events","type":"User","site_admin":false},"created_at":"2018-02-28T03:18:11Z","updated_at":"2018-02-28T03:18:11Z","author_association":"OWNER","body":"I just released the version 0.6.0 that covers this issue. Could you please check if it covers your use case?\r\n\r\nYou can check the full release description here:\r\nhttps://github.com/marcospassos/java-php-serializer/releases/tag/0.6.0\r\n\r\nI've also updated the docs to reflect the new feature:\r\nhttps://github.com/marcospassos/java-php-serializer\r\n\r\n"}}
{"actor":{"display_login":"marcospassos"}}