Fixed issues with HTML comments and Helma macros in Helma format functions.
This commit is contained in:
parent
1012b31a6a
commit
40ba46d788
1 changed files with 32 additions and 13 deletions
|
@ -18,14 +18,14 @@ import java.text.*;
|
||||||
public final class HtmlEncoder {
|
public final class HtmlEncoder {
|
||||||
|
|
||||||
// transformation table for characters 128 to 255. These actually fall into two
|
// transformation table for characters 128 to 255. These actually fall into two
|
||||||
// groups, put together for efficiency: "Windows" chacacters 128-159 such as
|
// groups, put together for efficiency: "Windows" chacacters 128-159 such as
|
||||||
// "smart quotes", which are encoded to valid Unicode entities, and
|
// "smart quotes", which are encoded to valid Unicode entities, and
|
||||||
// valid ISO-8859 caracters 160-255, which are encoded to the symbolic HTML
|
// valid ISO-8859 caracters 160-255, which are encoded to the symbolic HTML
|
||||||
// entity. Everything >= 256 is encoded to a numeric entity.
|
// entity. Everything >= 256 is encoded to a numeric entity.
|
||||||
//
|
//
|
||||||
// for mor on HTML entities see http://www.pemberley.com/janeinfo/latin1.html and
|
// for mor on HTML entities see http://www.pemberley.com/janeinfo/latin1.html and
|
||||||
// ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
|
// ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
|
||||||
//
|
//
|
||||||
static final String[] transform = {
|
static final String[] transform = {
|
||||||
"€", // 128
|
"€", // 128
|
||||||
"", // empty string means character is undefined in unicode
|
"", // empty string means character is undefined in unicode
|
||||||
|
@ -253,7 +253,6 @@ public final class HtmlEncoder {
|
||||||
allTags.add ("var");
|
allTags.add ("var");
|
||||||
allTags.add ("wbr");
|
allTags.add ("wbr");
|
||||||
allTags.add ("xmp");
|
allTags.add ("xmp");
|
||||||
allTags.add ("%");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tags which signal us to start suppressing \n -> <br> encoding
|
// tags which signal us to start suppressing \n -> <br> encoding
|
||||||
|
@ -304,6 +303,8 @@ public final class HtmlEncoder {
|
||||||
boolean insideCodeTag = false;
|
boolean insideCodeTag = false;
|
||||||
// are we within a macro tag?
|
// are we within a macro tag?
|
||||||
boolean insideMacroTag = false;
|
boolean insideMacroTag = false;
|
||||||
|
// are we inside an HTML comment?
|
||||||
|
boolean insideComment = false;
|
||||||
// the difference between swallowOneNewline and ignoreNewline is that
|
// the difference between swallowOneNewline and ignoreNewline is that
|
||||||
// swallowOneNewline is just effective once (for the next newline)
|
// swallowOneNewline is just effective once (for the next newline)
|
||||||
boolean ignoreNewline = false;
|
boolean ignoreNewline = false;
|
||||||
|
@ -346,10 +347,22 @@ public final class HtmlEncoder {
|
||||||
boolean insideCloseTag = ('/' == chars[i+1]);
|
boolean insideCloseTag = ('/' == chars[i+1]);
|
||||||
int tagStart = insideCloseTag ? i+2 : i+1;
|
int tagStart = insideCloseTag ? i+2 : i+1;
|
||||||
int j = tagStart;
|
int j = tagStart;
|
||||||
while (j<l && (Character.isLetterOrDigit (chars[j]) || chars[j] == '%'))
|
while (j<l && Character.isLetterOrDigit (chars[j]))
|
||||||
j++;
|
j++;
|
||||||
|
// if we haven't gotten past the <,
|
||||||
|
// check if it's an HTML comment or Helma macro tag
|
||||||
|
if (j == tagStart) {
|
||||||
|
if ('%' == chars[j]) {
|
||||||
|
insideMacroTag = insideTag = true;
|
||||||
|
ret.append ('<');
|
||||||
|
continue;
|
||||||
|
} else if (j < l-2 && '!' == chars[j] && '-' == chars[j+1] && '-' == chars[j+2]) {
|
||||||
|
insideComment = insideTag = true;
|
||||||
|
ret.append ('<');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (j > tagStart && j < l) {
|
if (j > tagStart && j < l) {
|
||||||
insideMacroTag = ('%' == chars[i+1]);
|
|
||||||
String tagName = new String (chars, tagStart, j-tagStart).toLowerCase ();
|
String tagName = new String (chars, tagStart, j-tagStart).toLowerCase ();
|
||||||
if ("code".equals (tagName) && insideCloseTag && insideCodeTag)
|
if ("code".equals (tagName) && insideCloseTag && insideCodeTag)
|
||||||
insideCodeTag = false;
|
insideCodeTag = false;
|
||||||
|
@ -385,11 +398,17 @@ public final class HtmlEncoder {
|
||||||
swallowOneNewline = false;
|
swallowOneNewline = false;
|
||||||
break;
|
break;
|
||||||
case '>':
|
case '>':
|
||||||
if (insideTag)
|
if (insideTag) {
|
||||||
ret.append ('>');
|
ret.append ('>');
|
||||||
else
|
if (insideMacroTag)
|
||||||
|
insideMacroTag = insideTag = !(chars[i-1] == '%');
|
||||||
|
else if (insideComment)
|
||||||
|
insideComment = insideTag = !(chars[i-2] == '-' && chars[i-1] == '-');
|
||||||
|
else
|
||||||
|
insideTag = false;
|
||||||
|
} else {
|
||||||
ret.append (">");
|
ret.append (">");
|
||||||
insideTag = insideMacroTag ? chars[i-1] != '%' : false;
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// ret.append (c);
|
// ret.append (c);
|
||||||
|
|
Loading…
Add table
Reference in a new issue