commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Garcia (JIRA)" <>
Subject [jira] Created: (LANG-617) StringEscapeUtils.escapeXML() can't process UTF-16 supplementary characters
Date Tue, 13 Apr 2010 15:25:49 GMT
StringEscapeUtils.escapeXML() can't process UTF-16 supplementary characters

                 Key: LANG-617
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.*
    Affects Versions: 2.4
            Reporter: David Garcia
            Priority: Minor

Supplementary characters in UTF-16 are those whose code points are above 0xffff, that is,
require more than 1 Java char to be encoded, as explained here:

Currently, StringEscapeUtils.escapeXML() isn't aware of this coding scheme and treats each
char as one character, which is not always right.

A possible solution in class Entities would be:

    public void escape(Writer writer, String str) throws IOException {
        int len = str.length();
        for (int i = 0; i < len; i++) {
            int code = str.codePointAt(i);
            String entityName = this.entityName(code);
            if (entityName != null) {
            } else if (code > 0x7F) {
            } else {
                    writer.write((char) code);

            if (code > 0xffff) {

Besides fixing escapeXML(), this will also affect HTML escaping functions. I guess that's
a good thing, but please remember I have only tested escapeXML().

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


View raw message