summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbar@mysql.com <>2006-03-20 14:57:34 +0400
committerbar@mysql.com <>2006-03-20 14:57:34 +0400
commit2e7cf881ace2595fb84afb643156e96016cd0793 (patch)
treef209b3c5a6738ea9d5c2ec741c26d967825e724c
parent95242e71862fd121e8ef1b3a7801d94fbd89a4eb (diff)
downloadmariadb-git-2e7cf881ace2595fb84afb643156e96016cd0793.tar.gz
Bug #18172 XML: Extractvalue() accepts mallformed
XPath without a XPath syntax error item_xmlfunc.cc: Error message didn't happen because after a failing attempt to parse RelativeLocationPath, my_xpath_parse_AbsoluteLocationPath() returned success. Changeing logic a bit: - Try to parse EOF first, return success if true. - Then try to parse RelativeLocationPath(), return success if true. - Otherwise return failure. xml.result: Adding test case. Also, this change made it possible to generate an error message earlier in the case of another bad XPATH syntax. xml.test: Adding test case.
-rw-r--r--mysql-test/r/xml.result4
-rw-r--r--mysql-test/t/xml.test9
-rw-r--r--sql/item_xmlfunc.cc5
3 files changed, 16 insertions, 2 deletions
diff --git a/mysql-test/r/xml.result b/mysql-test/r/xml.result
index d213ef98885..52f80000015 100644
--- a/mysql-test/r/xml.result
+++ b/mysql-test/r/xml.result
@@ -546,7 +546,7 @@ select extractvalue('<a>a<b>B</b></a>','a|/b');
extractvalue('<a>a<b>B</b></a>','a|/b')
a
select extractvalue('<a>A</a>','/<a>');
-ERROR HY000: XPATH syntax error: '>'
+ERROR HY000: XPATH syntax error: '<a>'
select extractvalue('<a><b>b</b><b!>b!</b!></a>','//b!');
ERROR HY000: XPATH syntax error: '!'
select extractvalue('<a>A<b>B<c>C</c></b></a>','/a/descendant::*');
@@ -613,3 +613,5 @@ select extractValue('<e>1</e>','position()');
ERROR HY000: XPATH syntax error: ''
select extractValue('<e>1</e>','last()');
ERROR HY000: XPATH syntax error: ''
+select extractValue('<e><a>1</a></e>','/e/');
+ERROR HY000: XPATH syntax error: ''
diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test
index ae1c9cf3b6b..af3ec2d827e 100644
--- a/mysql-test/t/xml.test
+++ b/mysql-test/t/xml.test
@@ -286,3 +286,12 @@ select extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]');
select extractValue('<e>1</e>','position()');
--error 1105
select extractValue('<e>1</e>','last()');
+
+
+#
+# Bug #18172 XML: Extractvalue() accepts mallformed
+# XPath without a XPath syntax error
+#
+--error 1105
+select extractValue('<e><a>1</a></e>','/e/');
+
diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc
index da39c1e4409..8e5efa9f0f5 100644
--- a/sql/item_xmlfunc.cc
+++ b/sql/item_xmlfunc.cc
@@ -1561,10 +1561,13 @@ static int my_xpath_parse_AbsoluteLocationPath(MY_XPATH *xpath)
return my_xpath_parse_RelativeLocationPath(xpath);
}
+ if (my_xpath_parse_term(xpath, MY_XPATH_LEX_EOF))
+ return 1;
+
if (my_xpath_parse_RelativeLocationPath(xpath))
return 1;
- return 1;
+ return 0;
}