Skip to content

Commit aa022ab

Browse files
committed
Add unit test with $.fromXml(string).
1 parent 3cb6f21 commit aa022ab

File tree

2 files changed

+24
-1
lines changed
  • lodash-plugin/src

2 files changed

+24
-1
lines changed

lodash-plugin/src/main/java/com/github/underscore/lodash/$.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,7 @@ private static Map<String, Object> createMap(final org.w3c.dom.Node node) {
25432543
} else {
25442544
value = currentNode.getTextContent();
25452545
}
2546-
if ("#text".equals(name) && value.toString().startsWith("\n")) {
2546+
if ("#text".equals(name) && value.toString().trim().isEmpty()) {
25472547
continue;
25482548
}
25492549
if (map.containsKey(name)) {

lodash-plugin/src/test/java/com/github/underscore/lodash/LodashTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,4 +800,27 @@ public String apply(Map<String, Object> item) {
800800
});
801801
assertEquals("[Fisrt, Second, third, fourth, fifth]", solutions.toString());
802802
}
803+
804+
@Test
805+
public void stackoverflow4() {
806+
// http://stackoverflow.com/questions/25085399/converting-xml-into-java-mapstring-integer
807+
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
808+
+ "<root>"
809+
+ " <Durapipe type=\"int\">1</Durapipe>"
810+
+ " <EXPLAIN type=\"int\">2</EXPLAIN>"
811+
+ " <woods type=\"int\">2</woods>"
812+
+ " <hanging type=\"int\">3</hanging>"
813+
+ " <hastily type=\"int\">2</hastily>"
814+
+ " <localized type=\"int\">1</localized>"
815+
+ " <Schuster type=\"int\">5</Schuster>"
816+
+ " <regularize type=\"int\">1</regularize>"
817+
+ " <LASR type=\"int\">1</LASR>"
818+
+ " <LAST type=\"int\">22</LAST>"
819+
+ " <Gelch type=\"int\">2</Gelch>"
820+
+ " <Gelco type=\"int\">26</Gelco>"
821+
+ "</root>";
822+
823+
assertEquals("{Durapipe=1, EXPLAIN=2, woods=2, hanging=3, hastily=2, localized=1, "
824+
+ "Schuster=5, regularize=1, LASR=1, LAST=22, Gelch=2, Gelco=26}", $.fromXml(xml).toString());
825+
}
803826
}

0 commit comments

Comments
 (0)