* 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");
|
swallowTwo.add("ul");
|
||||||
|
|
||||||
/// to be treated as block level elements
|
/// to be treated as block level elements
|
||||||
|
swallowTwo.add("br");
|
||||||
swallowTwo.add("dd");
|
swallowTwo.add("dd");
|
||||||
swallowTwo.add("dt");
|
swallowTwo.add("dt");
|
||||||
swallowTwo.add("frameset");
|
swallowTwo.add("frameset");
|
||||||
|
@ -322,6 +323,26 @@ public final class HtmlEncoder {
|
||||||
swallowAll.add("tr");
|
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,
|
* Do "smart" encodging on a string. This means that valid HTML entities and tags,
|
||||||
* Helma macros and HTML comments are passed through unescaped, while
|
* Helma macros and HTML comments are passed through unescaped, while
|
||||||
|
@ -470,9 +491,12 @@ public final class HtmlEncoder {
|
||||||
continue;
|
continue;
|
||||||
} else if (t > 1) {
|
} else if (t > 1) {
|
||||||
for (int k = 1; k < t; k++) {
|
for (int k = 1; k < t; k++) {
|
||||||
ret.append("</");
|
Object tag = openTags.pop();
|
||||||
ret.append(openTags.pop());
|
if (!emptyTags.contains(tag)) {
|
||||||
ret.append(">");
|
ret.append("</");
|
||||||
|
ret.append(tag);
|
||||||
|
ret.append(">");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,9 +683,12 @@ public final class HtmlEncoder {
|
||||||
|
|
||||||
if (o > 0) {
|
if (o > 0) {
|
||||||
for (int k = 0; k < o; k++) {
|
for (int k = 0; k < o; k++) {
|
||||||
ret.append("</");
|
Object tag = openTags.pop();
|
||||||
ret.append(openTags.pop());
|
if (!emptyTags.contains(tag)) {
|
||||||
ret.append(">");
|
ret.append("</");
|
||||||
|
ret.append(tag);
|
||||||
|
ret.append(">");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue