diff options
| author | Tom Lane | 2022-12-16 15:58:49 +0000 |
|---|---|---|
| committer | Tom Lane | 2022-12-16 16:10:40 +0000 |
| commit | 37bef842f5530fc9f4a48daba9f4709ee5e36c9b (patch) | |
| tree | 07537c49f5b6b0191a5f56537a69d1cc9e3382a9 /src/test | |
| parent | e52f8b301ed54aac5162b185b43f5f1e44b6b17e (diff) | |
Convert xml_in to report errors softly.
The key idea here is that xml_parse must distinguish hard errors
from soft errors. We want to throw a hard error for libxml
initialization failures: those might be out-of-memory, or something
else, but in any case they are not the fault of the input string.
If we get to the point of parsing the input, and something goes
wrong, we can fairly consider that to mean bad input.
One thing that arguably does mean bad input, but I didn't trouble
to handle softly, is encoding conversion failure while converting
the server encoding to UTF8. This might be something to improve
later, but it seems like a pretty low-probability scenario.
Discussion: https://postgr.es/m/3564577.1671142683@sss.pgh.pa.us
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/xml.out | 31 | ||||
| -rw-r--r-- | src/test/regress/expected/xml_1.out | 16 | ||||
| -rw-r--r-- | src/test/regress/expected/xml_2.out | 31 | ||||
| -rw-r--r-- | src/test/regress/sql/xml.sql | 7 |
4 files changed, 85 insertions, 0 deletions
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 948b4e702c1..a672e24daef 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -18,6 +18,37 @@ SELECT * FROM xmltest; 2 | <value>two</value> (2 rows) +-- test non-throwing API, too +SELECT pg_input_is_valid('<value>one</value>', 'xml'); + pg_input_is_valid +------------------- + t +(1 row) + +SELECT pg_input_is_valid('<value>one</', 'xml'); + pg_input_is_valid +------------------- + f +(1 row) + +SELECT pg_input_error_message('<value>one</', 'xml'); + pg_input_error_message +------------------------ + invalid XML content +(1 row) + +SELECT pg_input_is_valid('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); + pg_input_is_valid +------------------- + f +(1 row) + +SELECT pg_input_error_message('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); + pg_input_error_message +---------------------------------------------- + invalid XML content: invalid XML declaration +(1 row) + SELECT xmlcomment('test'); xmlcomment ------------- diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out index 2fce06069f2..378b412db00 100644 --- a/src/test/regress/expected/xml_1.out +++ b/src/test/regress/expected/xml_1.out @@ -22,6 +22,22 @@ SELECT * FROM xmltest; ----+------ (0 rows) +-- test non-throwing API, too +SELECT pg_input_is_valid('<value>one</value>', 'xml'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT pg_input_is_valid('<value>one</', 'xml'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT pg_input_error_message('<value>one</', 'xml'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT pg_input_is_valid('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. +SELECT pg_input_error_message('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); +ERROR: unsupported XML feature +DETAIL: This functionality requires the server to be built with libxml support. SELECT xmlcomment('test'); ERROR: unsupported XML feature DETAIL: This functionality requires the server to be built with libxml support. diff --git a/src/test/regress/expected/xml_2.out b/src/test/regress/expected/xml_2.out index 5fd3886b5ef..c55ea9a5934 100644 --- a/src/test/regress/expected/xml_2.out +++ b/src/test/regress/expected/xml_2.out @@ -16,6 +16,37 @@ SELECT * FROM xmltest; 2 | <value>two</value> (2 rows) +-- test non-throwing API, too +SELECT pg_input_is_valid('<value>one</value>', 'xml'); + pg_input_is_valid +------------------- + t +(1 row) + +SELECT pg_input_is_valid('<value>one</', 'xml'); + pg_input_is_valid +------------------- + f +(1 row) + +SELECT pg_input_error_message('<value>one</', 'xml'); + pg_input_error_message +------------------------ + invalid XML content +(1 row) + +SELECT pg_input_is_valid('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); + pg_input_is_valid +------------------- + f +(1 row) + +SELECT pg_input_error_message('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); + pg_input_error_message +---------------------------------------------- + invalid XML content: invalid XML declaration +(1 row) + SELECT xmlcomment('test'); xmlcomment ------------- diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index 484e3637e43..ddff4592973 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -9,6 +9,13 @@ INSERT INTO xmltest VALUES (3, '<wrong'); SELECT * FROM xmltest; +-- test non-throwing API, too +SELECT pg_input_is_valid('<value>one</value>', 'xml'); +SELECT pg_input_is_valid('<value>one</', 'xml'); +SELECT pg_input_error_message('<value>one</', 'xml'); +SELECT pg_input_is_valid('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); +SELECT pg_input_error_message('<?xml version="1.0" standalone="y"?><foo/>', 'xml'); + SELECT xmlcomment('test'); SELECT xmlcomment('-test'); |
