Skip to content

Commit

Permalink
Testcase for #981
Browse files Browse the repository at this point in the history
Closes #981

Fixed many, many moons ago.
  • Loading branch information
jhy committed Aug 27, 2024
1 parent d5debf8 commit d3104a0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/org/jsoup/helper/W3CDomTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,33 @@ public void canOutputHtmlWithoutNamespace() {
assertEquals("Foo", doc.getFirstChild().getTextContent());
}

@Test void testHtmlParseAttributesAreCaseInsensitive() throws IOException {
// https://github.com/jhy/jsoup/issues/981
String html = "<html lang=en>\n" +
"<body>\n" +
"<img src=\"firstImage.jpg\" alt=\"Alt one\" />\n" +
"<IMG SRC=\"secondImage.jpg\" AlT=\"Alt two\" />\n" +
"</body>\n" +
"</html>";
org.jsoup.nodes.Document jsoupDoc;
jsoupDoc = Jsoup.parse(html);
org.jsoup.helper.W3CDom jDom = new org.jsoup.helper.W3CDom();
Document doc = jDom.fromJsoup(jsoupDoc);
org.w3c.dom.Element body = (org.w3c.dom.Element) doc.getDocumentElement().getElementsByTagName("body").item(0);
NodeList imgs = body.getElementsByTagName("img");
assertEquals(2, imgs.getLength());
org.w3c.dom.Element first = (org.w3c.dom.Element) imgs.item(0);
assertEquals(first.getAttributes().getLength(), 2);
String img1 = first.getAttribute("src");
assertEquals("firstImage.jpg", img1);
String alt1 = first.getAttribute("alt");
assertEquals("Alt one", alt1);
org.w3c.dom.Element second = (org.w3c.dom.Element) imgs.item(1);
assertEquals(second.getAttributes().getLength(), 2);
String img2 = second.getAttribute("src");
assertEquals("secondImage.jpg", img2);
String alt2 = second.getAttribute("alt");
assertEquals("Alt two", alt2);
}

}

0 comments on commit d3104a0

Please sign in to comment.