Skip to content

Commit

Permalink
revise the "escaped" characters in XML/XHTML.
Browse files Browse the repository at this point in the history
Use   instead of   since it's also valid in xml.
  • Loading branch information
lhotari committed Apr 10, 2013
1 parent 2081313 commit 3f7afe2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Expand Up @@ -6,15 +6,18 @@

public class XMLEncoder extends AbstractCharReplacementEncoder {
static final String XML_CODEC_NAME="EscapedXML";
private static final String ESCAPED_BACKTICK = "&#" + ((int) '`') + ";";
private static final String ESCAPED_AT = "&#" + ((int) '@') + ";";
private static final String ESCAPED_EQUAL = "&#" + ((int) '=') + ";";
private static final String ESCAPED_PLUS = "&#" + ((int) '+') + ";";
private static final String ESCAPED_APOS = "&#" + ((int) '\'') + ";";
private static final String ESCAPED_APOS = "&#" + ((int) '\'') + ";"; // html doesn't have apos, so use numeric entity
private static final String ESCAPED_QUOTE = """;
private static final String ESCAPED_GT = ">";
private static final String ESCAPED_LT = "<";
private static final String ESCAPED_AMP = "&";
// some extras
private static final String ESCAPED_BACKSLASH = "&#" + ((int) '\\') + ";";
private static final char NBSP=(char)160;
private static final String ESCAPED_NON_BREAKING_SPACE = "&#" + ((int) NBSP) + ";";
private static final String ESCAPED_BACKTICK = "&#" + ((int) '`') + ";";
private static final String ESCAPED_AT = "&#" + ((int) '@') + ";"; // IE Javascript conditional compilation rules

private static final Set<String> equivalentCodecNames = new HashSet<String>(Arrays.asList(new String[]{"HTML4",HTMLCodec.CODEC_NAME}));

@Override
Expand All @@ -28,10 +31,10 @@ protected String escapeCharacter(char ch) {
case '>': return ESCAPED_GT;
case '"': return ESCAPED_QUOTE;
case '\'': return ESCAPED_APOS;
case '+': return ESCAPED_PLUS;
case '=': return ESCAPED_EQUAL;
case '@': return ESCAPED_AT;
case '\\': return ESCAPED_BACKSLASH;
case '@': return ESCAPED_AT;
case '`': return ESCAPED_BACKTICK;
case NBSP: return ESCAPED_NON_BREAKING_SPACE;
}
return null;
}
Expand Down
Expand Up @@ -215,7 +215,7 @@ enum Title implements org.springframework.context.MessageSourceResolvable {
// And then with French.
webRequest.currentRequest.addPreferredLocale(Locale.FRENCH)

assertOutputEquals '<input type="text" name="usPrice" value="1&nbsp;045,99" id="usPrice" />',
assertOutputEquals '<input type="text" name="usPrice" value="1&#160;045,99" id="usPrice" />',
template, [book:b]
}

Expand Down

0 comments on commit 3f7afe2

Please sign in to comment.