From 3010775ed19b6fbbbc2837e5ed8b377266c5533a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 17 Apr 2006 14:40:25 +0500 Subject: Bug#18201: XML: ExtractValue works even if the xml fragment is not well-formed xml Problem: - ExtractValue silently returned NULL if a wrong XML value is passed. - In some cases "unexpected END-OF-INPUT" error was not detected, and a non-NULL result could be returned for a bad XML value. Fix: - Adding warning messages, to make user aware why NULL was returned. - Missing "unexpected END-OF-INPUT" error is reported now. mysql-test/r/xml.result: - Fixing XML systax error in old test - Adding test cases. mysql-test/t/xml.test: - Fixing XML systax error in old test - Adding test cases. sql/item_xmlfunc.cc: Produce warning in case of XML systax error, instead of silentrly returning NULL. strings/xml.c: - Making error messages better looking and clearer: It is important because now they're seen in SHOW WARNINGS (previously they were used only for debugging purposes). - Adding "unexpected END-OF-INPUT" error if after scanning closing tag for the root element some input is left (previously this error was ignored in a mistake). --- mysql-test/r/xml.result | 32 +++++++++++++++++++++++++++++++- mysql-test/t/xml.test | 13 ++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'mysql-test') diff --git a/mysql-test/r/xml.result b/mysql-test/r/xml.result index 7e44673dd78..15daf7bb9b5 100644 --- a/mysql-test/r/xml.result +++ b/mysql-test/r/xml.result @@ -132,7 +132,7 @@ xb1 xc1 SELECT extractValue(@xml,'/a//@x[2]'); extractValue(@xml,'/a//@x[2]') xb2 xc2 -SET @xml='b1b2c1b1c1b2c2b1/a>'; +SET @xml='b1b2c1b1c1b2c2b1'; SELECT extractValue(@xml,'//b[1]'); extractValue(@xml,'//b[1]') b1 c1b1 c2b1 @@ -612,6 +612,36 @@ extractvalue('Jack' collate latin1_bin,'/a[contains(../a,"j")]') select ExtractValue('','/tag1'); ExtractValue('','/tag1') test +select extractValue('a','/a'); +extractValue('a','/a') +NULL +Warnings: +Warning 1504 Incorrect XML value: 'parse error at line 1 pos 5: unexpected END-OF-INPUT' +select extractValue('a<','/a'); +extractValue('a<','/a') +NULL +Warnings: +Warning 1504 Incorrect XML value: 'parse error at line 1 pos 6: END-OF-INPUT unexpected (ident or '/' wanted)' +select extractValue('aaaa' wanted)' +select extractValue('a','/a'); +extractValue('a','/a') +NULL +Warnings: +Warning 1504 Incorrect XML value: 'parse error at line 1 pos 12: '' unexpected (END-OF-INPUT wanted)' +select extractValue('a','/a'); +extractValue('a','/a') +NULL +Warnings: +Warning 1504 Incorrect XML value: 'parse error at line 1 pos 7: '>' unexpected (ident or string wanted)' select extractValue('1','position()'); ERROR HY000: XPATH syntax error: '' select extractValue('1','last()'); diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test index 8ed623883b6..af509a2f45e 100644 --- a/mysql-test/t/xml.test +++ b/mysql-test/t/xml.test @@ -53,7 +53,7 @@ SELECT extractValue(@xml,'/a//@x'); SELECT extractValue(@xml,'/a//@x[1]'); SELECT extractValue(@xml,'/a//@x[2]'); -SET @xml='b1b2c1b1c1b2c2b1/a>'; +SET @xml='b1b2c1b1c1b2c2b1'; SELECT extractValue(@xml,'//b[1]'); SELECT extractValue(@xml,'/descendant::b[1]'); @@ -284,6 +284,17 @@ select extractvalue('Jack' collate latin1_bin,'/a[contains(../a,"j")]'); # select ExtractValue('','/tag1'); +# +# Bug#18201: XML: ExtractValue works even if the xml fragment +# is not well-formed xml +# +select extractValue('a','/a'); +select extractValue('a<','/a'); +select extractValue('aaa','/a'); +select extractValue('a','/a'); + # # Bug #18171 XML: ExtractValue: the XPath position() # function crashes the server! -- cgit v1.2.1