Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 3D011B67AB3 for ; Fri, 27 Apr 2012 08:22:54 -0300 (ADT) Received: from mail-qc0-f174.google.com ([209.85.216.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SNjGG-0007tX-VE for pgsql-bugs@postgresql.org; Fri, 27 Apr 2012 11:22:53 +0000 Received: by qcro28 with SMTP id o28so291212qcr.19 for ; Fri, 27 Apr 2012 04:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=axbpSCuks2s6F+1Ss6Ytdg1SMJ8KHv7TAi4cmEWRZzM=; b=Xe9+dslr6hj9m/lpYpKbW3LAb/knSkNzwoRyqZzOGzlwenc6N9nWL4z7pAQBzGwBqY U7wTUNFoMASvHaqv+3U2GZ/rcCvTOVRDsXhynoEJI2poT93e9N9fBbPHzACDcuMBTf8w 9Wo/ho2ExmreYJYorDc2WnTM3NH0v+GiD9mGqZVrjQyS8BcGY1IpU9DeEoki4dJDiDis lVDONyxDbfBBFqH0gRYrSHRnMYjQHuGxFKKtKxm6X5JhJqsiv01+hPfcWEDyhYUwUpg8 lUX++F6omjsmxe7b5Yhfi9uM8oUoGPX09L4pU3fWXfTtS+qpTsu7bvpsr873qjjmd9lk NOkg== Received: by 10.229.135.213 with SMTP id o21mr1077161qct.31.1335525760183; Fri, 27 Apr 2012 04:22:40 -0700 (PDT) Received: from llserver.lakeliving.com (ool-18bbd2c6.static.optonline.net. [24.187.210.198]) by mx.google.com with ESMTPS id em10sm9869627qab.21.2012.04.27.04.22.38 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Apr 2012 04:22:38 -0700 (PDT) Date: Fri, 27 Apr 2012 07:22:35 -0400 From: Ryan Kelly To: Vik Reykja Cc: Tom Lane , pgsql-bugs@postgresql.org Subject: Re: hstore parser incorrectly handles malformed input Message-ID: <20120427112235.GA9024@llserver.lakeliving.com> References: <20120426190513.GB31886@llserver.lakeliving.com> <12884.1335469833@sss.pgh.pa.us> <19224.1335489137@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="82I3+IH0IqGh5yIs" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201204/182 X-Sequence-Number: 32933 --82I3+IH0IqGh5yIs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Apr 27, 2012 at 11:27:03AM +0200, Vik Reykja wrote: > On Fri, Apr 27, 2012 at 03:12, Tom Lane wrote: > > > Does anybody else have an opinion as to which of these solutions is > > more preferable? > > > > I think all unquoted whitespace should be ignored, so I prefer your > solution. (note: I haven't actually tested it, I'm going off these emails) As long as we make it consistent on both sides of the '=>' (and document it, too), then I don't really care either way. Currently you have to use quotes to get an empty key, so I thought it natural to that you should have to quote to get an empty value. I've attached a modified version of Tom's patch which also allows empty keys. > > > > And should we regard this as a back-patchable bug > > fix, or a definition change suitable only for HEAD? > > > > Since this is removing a syntax error and not creating one, I'd say it > should be safe to backpatch. -Ryan Kelly --82I3+IH0IqGh5yIs Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="hstore-empty-values-2.patch" diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index 0eb48cf..f03dcdc 100644 --- a/contrib/hstore/hstore_io.c +++ b/contrib/hstore/hstore_io.c @@ -74,7 +74,15 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped) } else if (*(state->ptr) == '=' && !ignoreeq) { - elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin)); + /* Empty key is perfectly OK */ + state->ptr--; + return true; + } + else if (*(state->ptr) == ',' && ignoreeq) + { + /* Empty value is perfectly OK */ + state->ptr--; + return true; } else if (*(state->ptr) == '\\') { @@ -191,7 +199,7 @@ parse_hstore(HSParser *state) if (st == WKEY) { if (!get_val(state, false, &escaped)) - return; + return; /* end of string */ if (state->pcur >= state->plen) { state->plen *= 2; @@ -236,7 +244,10 @@ parse_hstore(HSParser *state) else if (st == WVAL) { if (!get_val(state, true, &escaped)) - elog(ERROR, "Unexpected end of string"); + { + /* end of string, treat as empty value */ + state->ptr--; + } state->pairs[state->pcur].val = state->word; state->pairs[state->pcur].vallen = hstoreCheckValLen(state->cur - state->word); state->pairs[state->pcur].isnull = false; --82I3+IH0IqGh5yIs--