Skip to content

Commit 9e9e158

Browse files
committed
Don't parse <img> as <image> when in <svg>
Fixes jhy#364
1 parent c07ba8a commit 9e9e158

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ jsoup changelog
44
* Improved the performance of Element.text() by 2.2x
55

66
* If pretty-print is disabled, don't trim outer whitespace in Element.html()
7+
<https://github.com/jhy/jsoup/issues/368>
8+
9+
* Fixed an issue where <svg><img/></svg> was parsed as <svg><image/></svg>
10+
<https://github.com/jhy/jsoup/issues/364>
711

812
*** Release 1.7.3 [2013-Nov-10]
913
* Introduced FormElement, providing easy access to form controls and their data, and the ability to submit forms

src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,10 @@ boolean process(Token t, HtmlTreeBuilder tb) {
452452
tb.insertEmpty(startTag);
453453
tb.framesetOk(false);
454454
} else if (name.equals("image")) {
455-
// we're not supposed to ask.
456-
startTag.name("img");
457-
return tb.process(startTag);
455+
if (tb.getFromStack("svg") == null)
456+
return tb.process(startTag.name("img")); // change <image> to <img>, unless in svg
457+
else
458+
tb.insert(startTag);
458459
} else if (name.equals("isindex")) {
459460
// how much do we care about the early 90s?
460461
tb.error(this);

src/test/java/org/jsoup/parser/HtmlParserTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,4 +799,11 @@ public class HtmlParserTest {
799799
assertEquals(1, doc.select("table input").size());
800800
assertEquals(2, doc.select("input").size());
801801
}
802+
803+
@Test public void convertsImageToImg() {
804+
// image to img, unless in a svg. old html cruft.
805+
String h = "<body><image><svg><image /></svg></body>";
806+
Document doc = Jsoup.parse(h);
807+
assertEquals("<img />\n<svg>\n <image />\n</svg>", doc.body().html());
808+
}
802809
}

0 commit comments

Comments
 (0)