Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in regexp in function fixViewArgs : can not query with value like IP addresses #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

igit
Copy link

@igit igit commented Dec 8, 2010

We are working on a CouchDB server (1.0.1) with the Perl API CouchDB::Client (0.09).

When we create documents with a key that is an IP address :

---- CODE
my $ip = "192.168.100.1";
$cdb->newDoc($ip , undef, { user => "foobar"}, undef)->create;

print "argsToQuery=".$cdb->argsToQuery("key" => "$ip")."\n";
my $docs = $cdb->listDocs( "key" => "$ip" );

---- RESULTS
argsToQuery=?key=192.168.100.1

Connection error: 400 Bad Request at /usr/local/perl-5.8.8/lib/site_perl/5.8.8/CouchDB/Client/DB.pm line 114
CouchDB::Client::DB::listDocIdRevs('CouchDB::Client::DB=HASH(0x939c9a4)', 'key', 192.168.100.1) called at /usr/local/perl-5.8.8/lib/site_perl/5.8.8/CouchDB/Client/DB.pm line 129
CouchDB::Client::DB::listDocs('CouchDB::Client::DB=HASH(0x939c9a4)', 'key', 192.168.100.1) called at ./bar.pl line 34

and in the couch.log we have something like :

[Wed, 08 Dec 2010 09:35:18 GMT] [error] [<0.9484.6>] attempted upload of invalid JSON (set log_level to debug to log it)

===> the problem is in the function fixViewArgs that does not correctly takes care of IP address : the regexp "/^\d+(?:.\d+)$/s)" must be more strict to handle only integers or floats. If we change this regexp with "/^\d+(?:.){0,1}\d$/s" all will be ok for IP addresses.

Now, with this new regexp exp we have :

---- RESULTS
argsToQuery=?key=%22192.168.100.1%22

@maverick
Copy link
Owner

maverick commented Dec 8, 2010

As it turns out, someone else has posted a fix for this same problem using a very different approach (https://github.com/cdybedahl/couchdb-client). Obviously I've got to pick one solution or the other, so I'm trying to weigh the merits/pitfalls of each... In a vacuum, I would have used a regexp based solution, but cdybedahl's solution makes me wonder if there is a gotcha with using a regular expression that he's seeking to avoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants