Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xv6yB-0003QJ-5k for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Nov 2014 16:03:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xv6yA-0001a5-LQ for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Nov 2014 16:03:30 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xv6y8-0001WV-7P; Sun, 30 Nov 2014 16:03:28 +0000 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xv6y4-0002CL-Lt; Sun, 30 Nov 2014 16:03:26 +0000 Received: from mfilter5-d.gandi.net (mfilter5-d.gandi.net [217.70.178.132]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id EBC90A80B6; Sun, 30 Nov 2014 17:03:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter5-d.gandi.net Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by mfilter5-d.gandi.net (mfilter5-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id Txw9N3fuXN7h; Sun, 30 Nov 2014 17:03:19 +0100 (CET) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 5B7FFA80AF; Sun, 30 Nov 2014 17:03:18 +0100 (CET) Message-ID: <547B3FC4.8080509@dunslane.net> Date: Sun, 30 Nov 2014 11:03:16 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Tom Lane , bouda@edookit.com CC: pgsql-bugs@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: [BUGS] BUG #12070: hstore extension: hstore_to_json_loose produces invalid JSON References: <20141126081059.15510.5034@wrigleys.postgresql.org> <15817.1417018789@sss.pgh.pa.us> <54760440.2080501@dunslane.net> In-Reply-To: <54760440.2080501@dunslane.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 11/26/2014 11:48 AM, Andrew Dunstan wrote: > > On 11/26/2014 11:19 AM, Tom Lane wrote: >> bouda@edookit.com writes: >>> The hstore_to_json_loose(hstore) produces an invalid JSON in the >>> following >>> case: >>> SELECT hstore_to_json_loose(hstore(ARRAY ['name'], ARRAY ['1.'] :: TEXT >>> [])) >>> Output: {"name": 1.} >>> The actual output is indeed incorrect as JSON does not permit `1.` - >>> it must >>> be a string. >> Yeah. The problem seems to be the ad-hoc (I'm being polite) code in >> hstore_to_json_loose to decide whether a string should be treated as a >> number. It does much more work than it needs to, and fails to have any >> tight connection to the JSON syntax rules for numbers. >> >> Offhand, it seems like the nicest fix would be if the core json code >> exposed a function that would say whether a string matches the JSON >> number syntax. Does that functionality already exist someplace, >> or is it too deeply buried in the JSON parser guts? >> >> regards, tom lane >> >> > > > > In json.c we now check numbers like this: > > JsonLexContext dummy_lex; > bool numeric_error; > ... > dummy_lex.input = *outputstr == '-' ? outputstr + 1 : outputstr; > dummy_lex.input_length = strlen(dummy_lex.input); > json_lex_number(&dummy_lex, dummy_lex.input, &numeric_error); > > numeric_error is true IFF outputstr is a legal json number. > > Exposing a function to do this should be trivial. > > Tom, what do you want to do about this? In the back branches, exposing a function like this would be an API change, wouldn't it? Perhaps there we just need to pick up the 100 lines or so involved from json.c and copy them into hstore_io.c, suitably modified. In the development branch I thing adding the function to the API is the best way. I don't mind doing the work once we agree what is to be done - in the development branch it will be trivial. cheers andrew -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers