pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ryan Kelly <rpkelly22@gmail.com>
To: Vik Reykja <vikreykja@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: hstore parser incorrectly handles malformed input
Date: Fri, 27 Apr 2012 07:22:35 -0400
Message-ID: <20120427112235.GA9024@llserver.lakeliving.com> (raw)
In-Reply-To: <CALDgxVsZfSoWxHxpzsH22heJqwb6aom5x8kmVVe4WVq-fwTtOQ@mail.gmail.com>
References: <20120426190513.GB31886@llserver.lakeliving.com>
	<12884.1335469833@sss.pgh.pa.us>
	<19224.1335489137@sss.pgh.pa.us>
	<CALDgxVsZfSoWxHxpzsH22heJqwb6aom5x8kmVVe4WVq-fwTtOQ@mail.gmail.com>

On Fri, Apr 27, 2012 at 11:27:03AM +0200, Vik Reykja wrote:
> On Fri, Apr 27, 2012 at 03:12, Tom Lane <tgl@sss.pgh.pa.us> 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

Attachments:

hstore-empty-values-2.patch (text/x-diff, 1.3K) download 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;

view thread (9+ messages)  latest in thread

Message-ID: <20120427112235.GA9024@llserver.lakeliving.com>
Permalink:  ../20120427112235.GA9024@llserver.lakeliving.com/
Also on:    postgresql.org/message-id/20120427112235.GA9024@llserver.lakeliving.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: rpkelly22@gmail.com, vikreykja@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: hstore parser incorrectly handles malformed input
  In-Reply-To: <20120427112235.GA9024@llserver.lakeliving.com>
  References: <20120426190513.GB31886@llserver.lakeliving.com> <12884.1335469833@sss.pgh.pa.us> <19224.1335489137@sss.pgh.pa.us> <CALDgxVsZfSoWxHxpzsH22heJqwb6aom5x8kmVVe4WVq-fwTtOQ@mail.gmail.com> <20120427112235.GA9024@llserver.lakeliving.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox