couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neil Rahilly" <>
Subject Querying views with keys containing question marks
Date Mon, 03 Mar 2008 02:10:02 GMT

I'm very new to both erlang and couchdb, and am hesitant to write to
this list until I've learned more.  I think, though, that the
following from RFC 3986
(, may be relevant:

3.4. Query

   ...The query component is indicated by the first question
   mark ("?") character and terminated by a number sign ("#") character
   or by the end of the URI.

      query       = *( pchar / "/" / "?" )

   The characters slash ("/") and question mark ("?") may represent data
   within the query component.  Beware that some older, erroneous
   implementations may not handle such data correctly when it is used as
   the base URI for relative references (Section 5.1), apparently
   because they fail to distinguish query data from path data when
   looking for hierarchical separators.  However, as query components
   are often used to carry identifying information in the form of
   "key=value" pairs and one frequently used value is a reference to
   another URI, it is sometimes better for usability to avoid percent-
   encoding those characters.

Since only the first question mark in a URI should be treated as a
delimiter, and the rest are valid as data, the question mark in the
uri you are passing as a key (i.e., the second question mark in your
request uri) should be treated a data (and shouldn't necessarily need
to be percent encoded either).  Perhaps the particular needs of
couchdb may limit conformity to RFC 3986 though... as I said, I'm new

It looks as though the problem may stem from the call to

case regexp:split(RequestUri, "\\?") of

in the first line of src/CouchDB/mod_couch.erl.

I apologize if I'm way off base, but thought I'd toss this out there
in case it helped


> Hi
>  When querying a view using a key that contains a question mark I get
>  an error.
>  [info] [<0.92.0>] HTTP Request: GET /mydb/_view/feed/by_feed_url?key=
>  %22http:\/\/\/?feed=rss%22 HTTP/1.1
>  [info] [<0.92.0>] HTTP Error (code 500): {obj,[{error,"EXIT"},
>                               {reason,"{{case_clause,{ok,[\"/mydb/
>  _view/feed/by_feed_url\",\n
>  \"key=%22http:\\\\/\\\\/
>  \\\\/\",\"feed=rss%22\"]}},\n [{mod_couch,parse_uri,1},\n
>  {mod_couch,do,1},\n  {httpd_response,traverse_modules,2},\n
>  {httpd_response,generate_and_send_response,1},\n
>  {httpd_request_handler,handle_response,1},\n  {gen_server,handle_msg,
>  5},\n  {proc_lib,init_p,5}]}"}]}
>  [info] [<0.92.0>] HTTP Response Code:500
>  It seems the key is split up at the question mark but that isn't what
>  I intended!
>  The wiki says the values should be JSON encoded, but question marks
>  don't get encoded to my knowledge?
>  I tried substituting the question mark with %3F, which should be the
>  CGI escaped variant, but that clearly doesn't get converted back on
>  the couch db side because then it doesn't find the documents it is
>  supposed to find.
>  Any ideas how to fix this? Other than substituting question marks in
>  my data in the DB which I am going to use to use as keys?
>  Best regards
>  G

View raw message