Legal Characters for Document ID

223 views
Skip to first unread message

Andrew Tokarev

unread,
Jan 15, 2015, 6:11:06 AM1/15/15
to mobile-c...@googlegroups.com
I recently found out that custom doc_id is not validated on iOS/Android (might be true for other platforms). 
So it is possible to pass something like: "£%&-7", which causes exception on SyncGateway (no crash). 

Is this correct behaviour for Couchbase Lite frameworks?, I could not find anything about this on the web and in CBL documentation. 
But Database name is checked for legal characters: https://github.com/couchbase/couchbase-lite-ios/blob/master/Source/API/CBLManager.m#L376 (and it is written in the documentation)

---- Sync gateway (1.0.0) confused with some doc ids:
----
15:19:44.729250 CRUD+: Invoking sync on doc "£%&-7" rev 2-d36047fd7682b8f3255a0652ba510790
15:19:44.729562 CRUD+: No old revision "£%&-7" / "1-691feb51f7ea0da0c8e56132396a0451"
15:19:44.729856 WARNING: Sync fn exception: 400 Illegal channel name "person-£%&-7"; doc = map[_id:£%&-7 type:Person _revisions:map[start:%!s(float64=2) ids:[d36047fd7682b8f3255a0652ba510790 691feb51f7ea0da0c8e56132396a0451]] _rev:2-d36047fd7682b8f3255a0652ba510790] -- db.(*Database).getChannelsAndAccess() at crud.go:686
15:19:44.729873  BulkDocs: Doc "£%&-7" --> 500 Exception in JS sync function (500 Exception in JS sync function)


--- CBL lite library (1.0.3) can be confused too, but only when it is trying to sync it to GW.  
---
RemoteRequestCompletionBlock throw Exception
    java.lang.IllegalArgumentException: Invalid % sequence: %&- in path at index 31: http://10.69.31.233:7985/gw/£%&-7?new_edits=false
            at java.net.URI.create(URI.java:730)
            at org.apache.http.client.methods.HttpPut.<init>(HttpPut.java:71)
            at com.couchbase.lite.support.RemoteRequest.createConcreteRequest(RemoteRequest.java:146)

Jens Alfke

unread,
Jan 15, 2015, 11:30:40 AM1/15/15
to mobile-c...@googlegroups.com

On Jan 15, 2015, at 3:11 AM, Andrew Tokarev <andy.t...@gmail.com> wrote:

I recently found out that custom doc_id is not validated on iOS/Android (might be true for other platforms). 
So it is possible to pass something like: "£%&-7", which causes exception on SyncGateway (no crash). 

That is a valid document ID.


---- Sync gateway (1.0.0) confused with some doc ids:
----
15:19:44.729250 CRUD+: Invoking sync on doc "£%&-7" rev 2-d36047fd7682b8f3255a0652ba510790
15:19:44.729562 CRUD+: No old revision "£%&-7" / "1-691feb51f7ea0da0c8e56132396a0451"
15:19:44.729856 WARNING: Sync fn exception: 400 Illegal channel name "person-£%&-7"; doc = map[_id:£%&-7 type:Person _revisions:map[start:%!s(float64=2) ids:[d36047fd7682b8f3255a0652ba510790 691feb51f7ea0da0c8e56132396a0451]] _rev:2-d36047fd7682b8f3255a0652ba510790] -- db.(*Database).getChannelsAndAccess() at crud.go:686

…but that same string is an illegal channel ID. Doc and channel IDs are not the same thing. It can be convenient to name a channel after a document, but if you do that you need to ensure [on the client] that the document is given an ID that's a valid channel ID. Or your sync function could escape characters in the doc ID to make it a valid channel ID.

—Jens

Andrew Tokarev

unread,
Jan 21, 2015, 11:59:34 AM1/21/15
to mobile-c...@googlegroups.com
I decided to avoid special characters and spaces in doc_id, because of working with channels based on IDs is pretty common use case. 

Dominique Legault

unread,
Jan 22, 2015, 12:30:26 PM1/22/15
to mobile-c...@googlegroups.com
You can base64 encode the doc id for use as a channel.
Reply all
Reply to author
Forward
0 new messages