omegahat / RCurl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.mapUnicode can mangle JSON by unescaping backslashes

jmcphers opened this issue · comments

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.

Backslashes left alone when no Unicode present:

> cat(RCurl:::mapUnicodeEscapes("123\\\\456!"))
123\\456!

Backslashes unescaped when Unicode present:

> cat(RCurl:::mapUnicodeEscapes("123\\\\456\\u0021"))
123\456!

This behavior can mangle JSON payloads. For instance, this JSON is valid:

> cat(RCurl:::mapUnicodeEscapes("{\"!\": \"c:\\\\users\\\\bob\\\\\"}"))
{"!": "c:\\users\\bob\\"}

But if it contains Unicode, it becomes invalid:

> cat(RCurl:::mapUnicodeEscapes("{\"\\u0021\": \"c:\\\\users\\\\bob\\\\\"}"))
{"!": "c:\users\bob\"}