A question for the list:
I have an input form, which is handled via Struts and the input is validated,
URLEncoded with UTF-8 and stored in a DB
At a later date, the user can modify their input. The input is displayed with an
html:text tag, but unfortunately, it does not display properly.
Specifically, the issue is that a URLEncoded character like "堂" (堂, a
building in Traditional Chinese) is modified before being written out
It goes from "堂" to ""堂", which then displays incorrectly in the
browser.
Walking through the code, the BaseFieldTag class calls
results.append(ResponseUtils.filter(value.toString()));
which changes all "harmful" characters to HTML "friendly" ones. The filter method is
straightforward enough, but doesn't seem to handle the case where a '&' is followed
immediately by a '#' character. My first thought is to simply extend the HTML text
and textarea classes to add this simple case, but it seems like anyone working on a
multi-lingual site should have encountered this issue. (In other words, I can't be the
first guy to run into this, so I must be doing something wrong!)
Any suggestions? It seems that the html: tags are missing the filter attribute that
bean:write has, but again, I must be missing something...
I've pasted the filter method from ResponseUtils below.
Regards
Dave
public static String filter(String value) {
if (value == null)
return (null);
char content[] = new char[value.length()];
value.getChars(0, value.length(), content, 0);
StringBuffer result = new StringBuffer(content.length + 50);
for (int i = 0; i < content.length; i++) {
switch (content[i]) {
case '<':
result.append("<");
break;
case '>':
result.append(">");
break;
case '&':
result.append("&");
break;
case '"':
result.append(""");
break;
case '\'':
result.append("'");
break;
default:
result.append(content[i]);
}
}
return (result.toString());
}