incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: lexical error: invalid character inside string
Date Wed, 30 Jan 2013 08:17:40 GMT
As you specifically showed in your original email sending the two
bytes 0x5C72 (\r) from curl works correctly. Your R environment
appears to be doing various types of unescaping before sending the
data along to CouchDB which is what's causing you issues.

>From what you've shown the three characters 0x5C5C72 (\\r) works while
two bytes 0x5C72 (\r) and four bytes 0x5C5C5C72 (\\\r) do not work.
Most likely what is happening here is that R is unescaping your input.
Thus the three byte example 0x5C65C72 (\\r) is unescaped internally to
the two byte 0x5C72 (\r) sequence. Where as 0x5C72 (\r) and 0x5C5C5C72
(\\\r) are unescaped to 0x0D (carriage return) and 0x5C0D (\ and a
carriage return) respectively.

Basically, you need to work on your R un|escaping semantics to make
sure you're sending the right byte sequences to CouchDB. The easiest
way to accomplish this is to use a proper JSON library instead of
building JSON objects by hand.

HTH

On Wed, Jan 30, 2013 at 1:47 AM, Thomas Bock <thsteinbock@web.de> wrote:
>
> Thank you for the answer!
>
>> >  curl -X PUT --data '{"a": "\r"}' --header "Content-Type: application/json"
>> http://localhost:5984/r_test/ab7a
>>
>> I think JSON does not allow literal returns/newlines (or other
>> control characters) inside strings; they have to be backslash-
>
>  But the curl line works; and in futon I also can type in a simple \r
>
>> escaped. It’s hard to follow exactly what’s going on through all the
>> levels of quoting and unquoting that happen in the shell and in the
>> Erlang output, but I think you haven’t escaped that \r enough — it
>> probably needs to be "\\\r".
>
>  This ("\\\r") don't work; "\\r" works. Since \r is the end sign
> of a gauge (and it don't accept any other) for a measurement value query
> I need a reliable way.
>
>>
>> FYI, as a side note, I’ve found the ‘httpie’[1] utility a lifesaver
>> when talking to CouchDB (and other REST/JSON APIs) from the command
>> line. It’s like a souped-up curl with a much clearer syntax for
>> setting query parameters, and the ability to easily specify a JSON
>> body. For example, I can run your same command as:
>>
>>    http PUT :5984/r_test/ab7a a='\r’
>>
>> —Jens
>>
>> [1]: https://github.com/jkbr/httpie

Mime
View raw message