1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Fix handling of "undef" in contrib/jsonb_plperl.

Perl has multiple internal representations of "undef", and just
testing for SvTYPE(x) == SVt_NULL doesn't recognize all of them,
leading to "cannot transform this Perl type to jsonb" errors.
Use the approved test SvOK() instead.

Report and patch by Ivan Panchenko.  Back-patch to v11 where
this module was added.

Discussion: https://postgr.es/m/1564783533.324795401@f193.i.mail.ru
This commit is contained in:
Tom Lane
2019-08-04 14:05:35 -04:00
parent 4844c63032
commit df521ab795
5 changed files with 73 additions and 7 deletions

View File

@ -57,6 +57,19 @@ $$;
SELECT testRegexpResultToJsonb();
-- this revealed a different bug
CREATE FUNCTION testTextToJsonbObject(text) RETURNS jsonb
LANGUAGE plperl
TRANSFORM FOR TYPE jsonb
AS $$
my $x = shift;
return {a => $x};
$$;
SELECT testTextToJsonbObject('abc');
SELECT testTextToJsonbObject(NULL);
CREATE FUNCTION roundtrip(val jsonb, ref text = '') RETURNS jsonb
LANGUAGE plperl
TRANSFORM FOR TYPE jsonb

View File

@ -57,6 +57,19 @@ $$;
SELECT testRegexpResultToJsonb();
-- this revealed a different bug
CREATE FUNCTION testTextToJsonbObject(text) RETURNS jsonb
LANGUAGE plperlu
TRANSFORM FOR TYPE jsonb
AS $$
my $x = shift;
return {a => $x};
$$;
SELECT testTextToJsonbObject('abc');
SELECT testTextToJsonbObject(NULL);
CREATE FUNCTION roundtrip(val jsonb, ref text = '') RETURNS jsonb
LANGUAGE plperlu
TRANSFORM FOR TYPE jsonb