[JCBC-48] StringUtils.isJsonObject does not follow JSON spec which breaks Query Created: 13/May/12  Updated: 19/Jun/13  Resolved: 04/Oct/12

Status: Closed
Project: Couchbase Java Client
Component/s: Core
Affects Version/s: 1.1dp
Fix Version/s: 1.1-dp4
Security Level: Public

Type: Bug Priority: Blocker
Reporter: Steven Cooke Assignee: Michael Nitschinger
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment: all java


 Description   
net.spy.memcached.util.StringUtils does not implement isJsonObject to spec (http://www.json.org/) which breaks queries.

* In particular, valid JSON numbers outside of the Java integer range are rejected and any String starting with "{" or "[" is permitted.

* There is a size restriction for the key that is not checked (net.spy.memcached.util.validateKey)

* There is a related issue, http://www.couchbase.com/issues/browse/JCBC-41 related to quoting string keys, but I think there is confusion with what a valid key is that should be cleared up first. If setKey takes unquoted strings, but the query string requires a JSON string it should be clear in the docs and setKey should wrap and escape unquoted strings which will avoid special handling. Quoted strings passed to setKey should be treated as JSON and internal quotes if unescaped should probably be treated as a runtime exception at query time. Unless explicitly set elsewhere, only numeric types should by assumed to be JSON numbers.


Instead of isJsonObject and Object.toString, it may make sense to create isKey/toKey methods

isJsonObject should either be fixed or removed from spymemcached library, but the 2.8.1 version should never be used.


 


 Comments   
Comment by Steven Cooke [ 13/May/12 ]
I think fixing this will also fix http://www.couchbase.com/issues/browse/JCBC-40
Comment by Matt Ingenthron [ 24/Jul/12 ]
Excellent points, thanks for raising them. We're working to get an update here soon.
Comment by Tim Smith (Inactive) [ 17/Aug/12 ]
See related JCBC-32 .
Comment by Tim Smith (Inactive) [ 17/Aug/12 ]
Here's sample code that is difficult to get right:

https://gist.github.com/3375697

The setRangeStart() method needs to be called with an oddly-escaped JSON-encoded string:

myQuery.setRangeStart("[\"Level+2\"]");

This may be more relevant to JCBC-32.

This comment is to remind that somewhere in here is an opportunity to help the developer easily create the right query string without getting confused by multiple levels of quoting.

Thanks!

Tim
Comment by Michael Nitschinger [ 04/Oct/12 ]
This will be tracked in JCBC-41!
Comment by Brad Wood [ 19/Jun/13 ]
I'm unclear on whether or not the issue is resolved. The last comment says it will be tracked with JCBC-41, but that ticket doesn't appear to really be related to this one.
Generated at Mon Sep 22 17:07:07 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.