cloudant / java-cloudant

A Java client for Cloudant
Apache License 2.0
79 stars 68 forks source link

When using com.cloudant.client.api.Database.find(), a "+" in the document ID is not URL encoded #335

Closed stephenrobertson0 closed 7 years ago

stephenrobertson0 commented 7 years ago

When using com.cloudant.client.api.Database.find() and there is a "+" in the document id, the document does not get returned. It seems like the "+" is not getting URL encoded into "%2B", but other characters seem to be encoded correctly.

Using cloudant client 2.2.0, Sun Java 8, not using okhttp.

Code example:

database.find(Document.class, "id12+34");

ricellis commented 7 years ago

So this is interesting because the + character is allowed in the path segment of a URI by RFC3986 which are the rules we follow for encoding, but it appears that CouchDB (incorrectly IMO) follows the x-www-form-urlencoded practice of converting a + into a space. At best I think that should only apply in a query segment, not a path segment. I'll need to investigate whether this might get fixed on the CouchDB side, but because of backwards compatibility that seems unlikely and we may need to break with the URI spec and workaround.

ricellis commented 7 years ago

See also https://issues.apache.org/jira/browse/COUCHDB-1580

ricellis commented 7 years ago

Given that issue has been open since 2012 I think we probably ought to just workaround the issue.