[libxml2] Fix comparison of nodesets to strings
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Fix comparison of nodesets to strings
- Date: Sat, 7 Oct 2017 13:37:17 +0000 (UTC)
commit 5af594d8bc55121ae454cba4d05793d1db7ff612
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Sat Oct 7 14:54:45 2017 +0200
Fix comparison of nodesets to strings
Fix two bugs in xmlXPathNodeValHash which could lead to errors when
comparing nodesets to strings:
- Only use contents of text nodes to compute the hash for element nodes.
Comments, PIs, and other node types don't affect the string-value and
must be ignored.
- Reset `string` to NULL for node types other than text.
Reported by Aleksei on the mailing list:
https://mail.gnome.org/archives/xml/2017-September/msg00016.html
result/XPath/tests/strbase | 13 +++++++++++++
test/XPath/docs/str | 2 ++
test/XPath/tests/strbase | 1 +
xpath.c | 6 +-----
4 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/result/XPath/tests/strbase b/result/XPath/tests/strbase
new file mode 100644
index 0000000..e6035ca
--- /dev/null
+++ b/result/XPath/tests/strbase
@@ -0,0 +1,13 @@
+
+========================
+Expression: //p[.='abc']
+Object is a Node Set :
+Set contains 2 nodes:
+1 ELEMENT p
+ ATTRIBUTE id
+ TEXT
+ content=1
+2 ELEMENT p
+ ATTRIBUTE id
+ TEXT
+ content=2
diff --git a/test/XPath/docs/str b/test/XPath/docs/str
index 547e54d..449de01 100644
--- a/test/XPath/docs/str
+++ b/test/XPath/docs/str
@@ -6,4 +6,6 @@
<p><p>a span</p>n<p>ing one</p></p>
<p><p>and an unbal</p><empty/>anced test</p>
<p>for empty string <seq>123</seq></p>
+ <p id="1">a<b>b</b>c</p>
+ <p id="2"><!--X-->abc</p>
</chapter>
diff --git a/test/XPath/tests/strbase b/test/XPath/tests/strbase
new file mode 100644
index 0000000..b818325
--- /dev/null
+++ b/test/XPath/tests/strbase
@@ -0,0 +1 @@
+//p[.='abc']
diff --git a/xpath.c b/xpath.c
index b816bd3..55432c7 100644
--- a/xpath.c
+++ b/xpath.c
@@ -6400,16 +6400,12 @@ xmlXPathNodeValHash(xmlNodePtr node) {
}
while (tmp != NULL) {
switch (tmp->type) {
- case XML_COMMENT_NODE:
- case XML_PI_NODE:
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
string = tmp->content;
break;
- case XML_NAMESPACE_DECL:
- string = ((xmlNsPtr)tmp)->href;
- break;
default:
+ string = NULL;
break;
}
if ((string != NULL) && (string[0] != 0)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]