{"action":"opened","issue":{"url":"https://api.github.com/repos/omegahat/RCurl/issues/19","labels_url":"https://api.github.com/repos/omegahat/RCurl/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/omegahat/RCurl/issues/19/comments","events_url":"https://api.github.com/repos/omegahat/RCurl/issues/19/events","html_url":"https://github.com/omegahat/RCurl/issues/19","id":86683425,"number":19,"title":".mapUnicode can mangle JSON by unescaping backslashes","user":{"login":"jmcphers","id":470418,"avatar_url":"https://avatars.githubusercontent.com/u/470418?v=3","gravatar_id":"","url":"https://api.github.com/users/jmcphers","html_url":"https://github.com/jmcphers","followers_url":"https://api.github.com/users/jmcphers/followers","following_url":"https://api.github.com/users/jmcphers/following{/other_user}","gists_url":"https://api.github.com/users/jmcphers/gists{/gist_id}","starred_url":"https://api.github.com/users/jmcphers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmcphers/subscriptions","organizations_url":"https://api.github.com/users/jmcphers/orgs","repos_url":"https://api.github.com/users/jmcphers/repos","events_url":"https://api.github.com/users/jmcphers/events{/privacy}","received_events_url":"https://api.github.com/users/jmcphers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-09T18:06:18Z","updated_at":"2015-06-09T18:06:18Z","closed_at":null,"body":"In RCurl's `basicTextGatherer`, the `.mapUnicode` parameter acts on `\\uXXXX` sequences, according to the docs. It appears to have an unwanted side effect, however; it also unescapes backslashes if the text contains any Unicode escape sequences. \r\n\r\nBackslashes left alone when no Unicode present:\r\n\r\n    > cat(RCurl:::mapUnicodeEscapes(\"123\\\\\\\\456!\"))\r\n    123\\\\456!\r\n\r\nBackslashes unescaped when Unicode present:\r\n\r\n    > cat(RCurl:::mapUnicodeEscapes(\"123\\\\\\\\456\\\\u0021\"))\r\n    123\\456!\r\n\r\nThis behavior can mangle JSON payloads. For instance, this JSON is valid:\r\n\r\n    > cat(RCurl:::mapUnicodeEscapes(\"{\\\"!\\\": \\\"c:\\\\\\\\users\\\\\\\\bob\\\\\\\\\\\"}\"))\r\n    {\"!\": \"c:\\\\users\\\\bob\\\\\"}\r\n\r\nBut if it contains Unicode, it becomes invalid:\r\n\r\n    > cat(RCurl:::mapUnicodeEscapes(\"{\\\"\\\\u0021\\\": \\\"c:\\\\\\\\users\\\\\\\\bob\\\\\\\\\\\"}\"))\r\n    {\"!\": \"c:\\users\\bob\\\"}\r\n\r\n"}}