From 840729fd104e6ff35e0a6ebcf06ad053403a96f5 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 18 Mar 2022 16:01:42 -0400 Subject: [PATCH] Fix incorrect xmlschema output for types timetz and timestamptz. The output of table_to_xmlschema() and allied functions includes a regex describing valid values for these types ... but the regex was itself invalid, as it failed to escape a literal "+" sign. Report and fix by Renan Soares Lopes. Back-patch to all supported branches. Discussion: https://postgr.es/m/7f6fabaa-3f8f-49ab-89ca-59fbfe633105@me.com --- src/backend/utils/adt/xml.c | 4 +- src/test/regress/expected/xmlmap.out | 928 +++++++++++++------------ src/test/regress/expected/xmlmap_1.out | 10 +- src/test/regress/sql/xmlmap.sql | 10 +- 4 files changed, 514 insertions(+), 438 deletions(-) diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index d43c3055f3..83f53134a7 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -3673,7 +3673,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) case TIMEOID: case TIMETZOID: { - const char *tz = (typeoid == TIMETZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); + const char *tz = (typeoid == TIMETZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); if (typmod == -1) appendStringInfo(&result, @@ -3696,7 +3696,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) case TIMESTAMPOID: case TIMESTAMPTZOID: { - const char *tz = (typeoid == TIMESTAMPTZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); + const char *tz = (typeoid == TIMESTAMPTZOID ? "(\\+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); if (typmod == -1) appendStringInfo(&result, diff --git a/src/test/regress/expected/xmlmap.out b/src/test/regress/expected/xmlmap.out index c08f8a0d9c..ccc5460663 100644 --- a/src/test/regress/expected/xmlmap.out +++ b/src/test/regress/expected/xmlmap.out @@ -2,9 +2,15 @@ CREATE SCHEMA testxmlschema; CREATE TABLE testxmlschema.test1 (a int, b text); INSERT INTO testxmlschema.test1 VALUES (1, 'one'), (2, 'two'), (-1, null); CREATE DOMAIN testxmldomain AS varchar; -CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), w numeric(9,2), v smallint, u bigint, t real, s time, r timestamp, q date, p xml, o testxmldomain, n bool, m bytea, aaa text); +CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), + w numeric(9,2), v smallint, u bigint, t real, + s time, stz timetz, r timestamp, rtz timestamptz, q date, + p xml, o testxmldomain, n bool, m bytea, aaa text); ALTER TABLE testxmlschema.test2 DROP COLUMN aaa; -INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', 98.6, 2, 999, 0, '21:07', '2009-06-08 21:07:30', '2009-06-08', NULL, 'ABC', true, 'XYZ'); +INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', + 98.6, 2, 999, 0, + '21:07', '21:11 +05', '2009-06-08 21:07:30', '2009-06-08 21:07:30 -07', '2009-06-08', + NULL, 'ABC', true, 'XYZ'); SELECT table_to_xml('testxmlschema.test1', false, false, ''); table_to_xml --------------------------------------------------------------- @@ -107,7 +113,9 @@ SELECT table_to_xml('testxmlschema.test2', false, false, ''); 999 + 0 + 21:07:00 + + 21:11:00+05 + 2009-06-08T21:07:30 + + 2009-06-08T21:07:30-07:00 + 2009-06-08 + ABC + true + @@ -253,113 +261,127 @@ SELECT table_to_xmlschema('testxmlschema.test1', true, true, ''); (1 row) SELECT table_to_xmlschema('testxmlschema.test2', false, false, ''); - table_to_xmlschema ------------------------------------------------------------------------------------------------------------------ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + table_to_xmlschema +---------------------------------------------------------------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (1 row) @@ -816,7 +838,9 @@ SELECT schema_to_xml('testxmlschema', false, true, ''); 999 + 0 + 21:07:00 + + 21:11:00+05 + 2009-06-08T21:07:30 + + 2009-06-08T21:07:30-07:00 + 2009-06-08 + ABC + true + @@ -863,7 +887,9 @@ SELECT schema_to_xml('testxmlschema', true, false, ''); 999 + 0 + 21:07:00 + + 21:11:00+05 + 2009-06-08T21:07:30 + + 2009-06-08T21:07:30-07:00 + 2009-06-08 +

+ ABC + @@ -878,337 +904,375 @@ SELECT schema_to_xml('testxmlschema', true, false, ''); (1 row) SELECT schema_to_xmlschema('testxmlschema', false, true, ''); - schema_to_xmlschema -------------------------------------------------------------------------------------------------------------------- - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + schema_to_xmlschema +---------------------------------------------------------------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (1 row) SELECT schema_to_xmlschema('testxmlschema', true, false, ''); - schema_to_xmlschema ---------------------------------------------------------------------------------------------------- - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + schema_to_xmlschema +---------------------------------------------------------------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (1 row) SELECT schema_to_xml_and_xmlschema('testxmlschema', true, true, 'foo'); - schema_to_xml_and_xmlschema -------------------------------------------------------------------------------------------------------------------- - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - 1 + - one + - + - + - + - 2 + - two + - + - + - + - -1 + - + - + - + - + - + - 55 + - abc + - def + - 98.60 + - 2 + - 999 + - 0 + - 21:07:00 + - 2009-06-08T21:07:30 + - 2009-06-08 + -

+ - ABC + - true + - WFla + - + - + - + - + + schema_to_xml_and_xmlschema +---------------------------------------------------------------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + one + + + + + + + + 2 + + two + + + + + + + + -1 + + + + + + + + + + + + 55 + + abc + + def + + 98.60 + + 2 + + 999 + + 0 + + 21:07:00 + + 21:11:00+05 + + 2009-06-08T21:07:30 + + 2009-06-08T21:07:30-07:00 + + 2009-06-08 + +

+ + ABC + + true + + WFla + + + + + + + + + (1 row) diff --git a/src/test/regress/expected/xmlmap_1.out b/src/test/regress/expected/xmlmap_1.out index f6dbf81666..4504acd377 100644 --- a/src/test/regress/expected/xmlmap_1.out +++ b/src/test/regress/expected/xmlmap_1.out @@ -2,9 +2,15 @@ CREATE SCHEMA testxmlschema; CREATE TABLE testxmlschema.test1 (a int, b text); INSERT INTO testxmlschema.test1 VALUES (1, 'one'), (2, 'two'), (-1, null); CREATE DOMAIN testxmldomain AS varchar; -CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), w numeric(9,2), v smallint, u bigint, t real, s time, r timestamp, q date, p xml, o testxmldomain, n bool, m bytea, aaa text); +CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), + w numeric(9,2), v smallint, u bigint, t real, + s time, stz timetz, r timestamp, rtz timestamptz, q date, + p xml, o testxmldomain, n bool, m bytea, aaa text); ALTER TABLE testxmlschema.test2 DROP COLUMN aaa; -INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', 98.6, 2, 999, 0, '21:07', '2009-06-08 21:07:30', '2009-06-08', NULL, 'ABC', true, 'XYZ'); +INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', + 98.6, 2, 999, 0, + '21:07', '21:11 +05', '2009-06-08 21:07:30', '2009-06-08 21:07:30 -07', '2009-06-08', + NULL, 'ABC', true, 'XYZ'); SELECT table_to_xml('testxmlschema.test1', false, false, ''); ERROR: unsupported XML feature DETAIL: This functionality requires the server to be built with libxml support. diff --git a/src/test/regress/sql/xmlmap.sql b/src/test/regress/sql/xmlmap.sql index fde1b9eb59..16582bf6ab 100644 --- a/src/test/regress/sql/xmlmap.sql +++ b/src/test/regress/sql/xmlmap.sql @@ -3,9 +3,15 @@ CREATE SCHEMA testxmlschema; CREATE TABLE testxmlschema.test1 (a int, b text); INSERT INTO testxmlschema.test1 VALUES (1, 'one'), (2, 'two'), (-1, null); CREATE DOMAIN testxmldomain AS varchar; -CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), w numeric(9,2), v smallint, u bigint, t real, s time, r timestamp, q date, p xml, o testxmldomain, n bool, m bytea, aaa text); +CREATE TABLE testxmlschema.test2 (z int, y varchar(500), x char(6), + w numeric(9,2), v smallint, u bigint, t real, + s time, stz timetz, r timestamp, rtz timestamptz, q date, + p xml, o testxmldomain, n bool, m bytea, aaa text); ALTER TABLE testxmlschema.test2 DROP COLUMN aaa; -INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', 98.6, 2, 999, 0, '21:07', '2009-06-08 21:07:30', '2009-06-08', NULL, 'ABC', true, 'XYZ'); +INSERT INTO testxmlschema.test2 VALUES (55, 'abc', 'def', + 98.6, 2, 999, 0, + '21:07', '21:11 +05', '2009-06-08 21:07:30', '2009-06-08 21:07:30 -07', '2009-06-08', + NULL, 'ABC', true, 'XYZ'); SELECT table_to_xml('testxmlschema.test1', false, false, ''); SELECT table_to_xml('testxmlschema.test1', true, false, 'foo');