Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-92: better handling of Attributes in DOMUtils.getText

Chris M. Hostettere44e51ece018
diff --git a/CHANGES.txt b/CHANGES.txt
index 98043e4d0ca..330e8fe6f14 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -46,6 +46,9 @@ Optimizations
Bug Fixes
1. SOLR-87: Parsing of synonym files did not correctly handle escaped
whitespace such as \r\n\t\b\f. (yonik)
+ 2. SOLR-92: DOMUtils.getText (used when parsing config files) did not
+ work properly with many DOM implementations when dealing with
+ "Attributes". (Ryan McKinley via hossman)
Other Changes
1.
diff --git a/src/java/org/apache/solr/util/DOMUtil.java b/src/java/org/apache/solr/util/DOMUtil.java
index 3e561c59823..12531e3d515 100644
--- a/src/java/org/apache/solr/util/DOMUtil.java
+++ b/src/java/org/apache/solr/util/DOMUtil.java
@@ -189,7 +189,6 @@ public class DOMUtil {
switch (type) {
case Node.ELEMENT_NODE: /* fall through */
- case Node.ATTRIBUTE_NODE: /* fall through */
case Node.ENTITY_NODE: /* fall through */
case Node.ENTITY_REFERENCE_NODE: /* fall through */
case Node.DOCUMENT_FRAGMENT_NODE:
@@ -204,6 +203,20 @@ public class DOMUtil {
}
break;
+ case Node.ATTRIBUTE_NODE: /* fall through */
+ /* Putting Attribute nodes in this section does not exactly
+ match the definition of how textContent should behave
+ according to the DOM Level-3 Core documentation - which
+ specifies that the Attr's children should have their
+ textContent concated (Attr's can have a single child which
+ is either Text node or an EntityRefrence). In practice,
+ DOM implementations do not seem to use child nodes of
+ Attributes, storing the "text" directly as the nodeValue.
+ Fortunately, the DOM Spec indicates that when Attr.nodeValue
+ is read, it should return the nodeValue from the child Node,
+ so this approach should work both for strict implementations,
+ and implementations actually encountered.
+ */
case Node.TEXT_NODE: /* fall through */
case Node.CDATA_SECTION_NODE: /* fall through */
case Node.COMMENT_NODE: /* fall through */