* Added list of empty HTML tags which are never closed in tag balancing code.
* Added <br> to the list of pseudo-block elements to prevent further <br> tags to be generated if there already are any in the text.
This commit is contained in:
parent
f2c51c8e32
commit
6b92af2ae0
1 changed files with 33 additions and 6 deletions
|
@ -310,6 +310,7 @@ public final class HtmlEncoder {
|
|||
swallowTwo.add("ul");
|
||||
|
||||
/// to be treated as block level elements
|
||||
swallowTwo.add("br");
|
||||
swallowTwo.add("dd");
|
||||
swallowTwo.add("dt");
|
||||
swallowTwo.add("frameset");
|
||||
|
@ -322,6 +323,26 @@ public final class HtmlEncoder {
|
|||
swallowAll.add("tr");
|
||||
}
|
||||
|
||||
// set of tags that are always empty
|
||||
static final HashSet emptyTags = new HashSet();
|
||||
|
||||
static {
|
||||
emptyTags.add("area");
|
||||
emptyTags.add("base");
|
||||
emptyTags.add("basefont");
|
||||
emptyTags.add("br");
|
||||
emptyTags.add("col");
|
||||
emptyTags.add("frame");
|
||||
emptyTags.add("hr");
|
||||
emptyTags.add("img");
|
||||
emptyTags.add("input");
|
||||
emptyTags.add("isindex");
|
||||
emptyTags.add("link");
|
||||
emptyTags.add("meta");
|
||||
emptyTags.add("param");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do "smart" encodging on a string. This means that valid HTML entities and tags,
|
||||
* Helma macros and HTML comments are passed through unescaped, while
|
||||
|
@ -470,11 +491,14 @@ public final class HtmlEncoder {
|
|||
continue;
|
||||
} else if (t > 1) {
|
||||
for (int k = 1; k < t; k++) {
|
||||
Object tag = openTags.pop();
|
||||
if (!emptyTags.contains(tag)) {
|
||||
ret.append("</");
|
||||
ret.append(openTags.pop());
|
||||
ret.append(tag);
|
||||
ret.append(">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openTags.pop();
|
||||
} else {
|
||||
|
@ -659,11 +683,14 @@ public final class HtmlEncoder {
|
|||
|
||||
if (o > 0) {
|
||||
for (int k = 0; k < o; k++) {
|
||||
Object tag = openTags.pop();
|
||||
if (!emptyTags.contains(tag)) {
|
||||
ret.append("</");
|
||||
ret.append(openTags.pop());
|
||||
ret.append(tag);
|
||||
ret.append(">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add remaining newlines we may have collected
|
||||
if ((linebreaks > 0) && (linebreaks > swallowLinebreaks)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue