Skip to content

Commit

Permalink
Test for #1170 text node content
Browse files Browse the repository at this point in the history
No repro.
  • Loading branch information
jhy committed Feb 19, 2020
1 parent 5d864bd commit 50fae5b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/test/java/org/jsoup/nodes/TextNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jsoup.Jsoup;
import org.jsoup.TextUtil;
import org.jsoup.internal.StringUtil;
import org.junit.Test;

import java.util.List;
Expand Down Expand Up @@ -135,4 +136,25 @@ public void testCloneAfterAttributesHit() {
assertEquals("zzz", x.text());
assertEquals("xxx", y.text());
}

@Test
public void testHasTextWhenIterating() {
// https://github.com/jhy/jsoup/issues/1170
Document doc = Jsoup.parse("<div>One <p>Two <p>Three");
boolean foundFirst = false;
for (Element el : doc.getAllElements()) {
for (Node node : el.childNodes()) {
if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
assertFalse(StringUtil.isBlank(textNode.text()));
if (!foundFirst) {
foundFirst = true;
assertEquals("One ", textNode.text());
assertEquals("One ", textNode.getWholeText());
}
}
}
}
assertTrue(foundFirst);
}
}

0 comments on commit 50fae5b

Please sign in to comment.