Skip to content

Commit

Permalink
Parse unknown tags as inline elements that can contain blocks.
Browse files Browse the repository at this point in the history
Ensures <p><custom>Test</custom></p> parses like that, and not
<p></p><custom>Test</custom>.

Closes #1
  • Loading branch information
jhy committed Feb 1, 2010
1 parent bc4a9ce commit b19d83f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/org/jsoup/parser/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ public static Tag valueOf(String tagName) {
synchronized (tags) {
Tag tag = tags.get(tagName);
if (tag == null) {
// not defined: create default
// not defined: create default; go anywhere, do anything! (incl be inside a <p>)
tag = new Tag(tagName);
tag.setAncestor(defaultAncestor.tagName);
tag.isBlock = false;
tag.canContainBlock = true;
}
return tag;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/jsoup/org/jsoup/safety/CleanerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ public class CleanerTest {
String cleanHtml = Jsoup.clean(h, Whitelist.relaxed());
assertEquals("<a>XSS</a>", cleanHtml);
}

@Test public void testDropsUnknownTags() {
String h = "<p><custom foo=true>Test</custom></p>";
String cleanHtml = Jsoup.clean(h, Whitelist.relaxed());
assertEquals("<p>Test</p>", cleanHtml);
}
}
7 changes: 7 additions & 0 deletions src/test/java/org/jsoup/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ public class ParserTest {
assertEquals("qux", foos.last().attr("title"));
assertEquals("there", foos.last().text());
}

@Test public void handlesUnknownInlineTags() {
String h = "<p><cust>Test</cust></p><p><cust><cust>Test</cust></cust></p>";
Document doc = Jsoup.parseBodyFragment(h);
String out = doc.body().html();
assertEquals(h, TextUtil.stripNewlines(out));
}

@Test public void handlesEmptyBlocks() {
String h = "<div id=1/><div id=2><img /></div>";
Expand Down

0 comments on commit b19d83f

Please sign in to comment.