From 6b92af2ae02359271fe5ccc5123c90d37c5a5640 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 6 Jun 2003 13:41:17 +0000 Subject: [PATCH] * Added list of empty HTML tags which are never closed in tag balancing code. * Added
to the list of pseudo-block elements to prevent further
tags to be generated if there already are any in the text. --- src/helma/util/HtmlEncoder.java | 39 ++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/helma/util/HtmlEncoder.java b/src/helma/util/HtmlEncoder.java index be2431dc..9c1bb6c4 100644 --- a/src/helma/util/HtmlEncoder.java +++ b/src/helma/util/HtmlEncoder.java @@ -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,9 +491,12 @@ public final class HtmlEncoder { continue; } else if (t > 1) { for (int k = 1; k < t; k++) { - ret.append(""); + Object tag = openTags.pop(); + if (!emptyTags.contains(tag)) { + ret.append(""); + } } } @@ -659,9 +683,12 @@ public final class HtmlEncoder { if (o > 0) { for (int k = 0; k < o; k++) { - ret.append(""); + Object tag = openTags.pop(); + if (!emptyTags.contains(tag)) { + ret.append(""); + } } }