From d5debf82efb35bca3b82aaa72405dfdae8a620df Mon Sep 17 00:00:00 2001 From: Jonathan Hedley Date: Tue, 27 Aug 2024 20:14:06 +1000 Subject: [PATCH] Test for #1998 Closes #1998 Was fixed by #2146 --- src/test/java/org/jsoup/nodes/ElementTest.java | 13 ++++++++++++- src/test/java/org/jsoup/select/SelectorTest.java | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index de35495ff1..783cdb4e3e 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -26,6 +26,7 @@ import java.util.regex.Pattern; import java.util.stream.Stream; +import static org.jsoup.select.SelectorTest.assertSelectedOwnText; import static org.junit.jupiter.api.Assertions.*; /** @@ -2636,7 +2637,7 @@ void prettySerializationRoundTrips(Document.OutputSettings settings) { assertEquals(selected.first(), div); } - @Test void cssSelectorWithAstrix() { + @Test void cssSelectorWithAsterisk() { // https://github.com/jhy/jsoup/issues/2169 Document doc = Jsoup.parse("
One
Two
"); Element div = doc.expectFirst("div"); @@ -2648,6 +2649,16 @@ void prettySerializationRoundTrips(Document.OutputSettings settings) { assertEquals(selected.first(), div); } + @Test void cssSelectorWithPipe() { + // https://github.com/jhy/jsoup/issues/1998 + Document doc = Jsoup.parse("
One
"); + Element span = doc.expectFirst("div span"); + String selector = span.cssSelector(); + assertEquals("html > body > div > span.\\|", selector); + Elements selected = doc.select(selector); + assertSelectedOwnText(selected, "One"); + } + @Test void orphanSiblings() { Element el = new Element("div"); assertEquals(0, el.siblingElements().size()); diff --git a/src/test/java/org/jsoup/select/SelectorTest.java b/src/test/java/org/jsoup/select/SelectorTest.java index d296e1a2b7..7eca896793 100644 --- a/src/test/java/org/jsoup/select/SelectorTest.java +++ b/src/test/java/org/jsoup/select/SelectorTest.java @@ -28,7 +28,7 @@ public static void assertSelectedIds(Elements els, String... ids) { } } - static void assertSelectedOwnText(Elements els, String... ownTexts) { + public static void assertSelectedOwnText(Elements els, String... ownTexts) { assertNotNull(els); assertEquals(ownTexts.length, els.size(), "Incorrect number of selected elements"); for (int i = 0; i < ownTexts.length; i++) {