[jira] Commented: (SOAP-159) Axis mis-encodes Strings w/ invalid characters for SOAP transport
"Jeremy Kleier (JIRA)" <[email protected]> Fri, 14 Jul 2006 08:53:14 -0700 (PDT)
| Newsgroups | gmane.text.xml.soap.devel |
|---|---|
| Message-ID | <10415854.1152892394898.JavaMail.jira@brutus> |
[ http://issues.apache.org/jira/browse/SOAP-159?page=3Dcomments#action_=
12421139 ]=20
=20
Jeremy Kleier commented on SOAP-159:
------------------------------------
I have a related issue with this piece of code:
case '\r' : strBuf.append("
");
break;
I don't believe escaping the carriage return is the proper thing to do here=
. Carriage returns *are* valid XML chars, and all that we should be doing i=
n this piece of code is cleaning the message to be valid XML.
Jeremy Kleier
[email protected]
> Axis mis-encodes Strings w/ invalid characters for SOAP transport
> -----------------------------------------------------------------
>
> Key: SOAP-159
> URL: http://issues.apache.org/jira/browse/SOAP-159
> Project: SOAP
> Issue Type: Bug
> Components: All
> Affects Versions: 2.2
> Environment: Operating System: Windows XP
> Platform: PC
> Reporter: Ryan Choi
> Assigned To: Matthew J. Duftler
>
> Axis doesn=C3=A2=C2=80=C2=99t seem to be properly XML-encoding string val=
ues in SOAP=20
> requests/responses. More specifically, org.apache.axis.utils.XmlUtils isn=
't=20
> stripping out invalid characters before sending them across the wire. An=
=20
> example of such an invalid string is:
> 2002=C3=A2=C2=80=C2=9DN2=C3=85'=C3=85=C2=BD1=C3=A2=C2=80=C2=9C=C3=83=C2=
=BA=C3=82=C2=B3=C3=85=C2=BD=C3=82=C2=AE=C3=85'_=C3=A2=C2=80"=C3=83=C2=B1=C3=
=A2=C2=80=C2=A2=C3=82=C2=AA=C3=A2=C2=80=C2=9A=C3=83=C2=A6=C3=A2=C2=80=C2=9A=
=C3=83=C2=A8=C3=83...=C3=82=C2=AC=C3=86'=C3=A2=C2=80=C2=B0=C3=86'C=C3=86'Z=
=C3=86'=C3=A2=C2=80=C2=9C=C3=86'X=C3=A2=C2=80=C2=9D=C3=A2=C2=80=C2=9A=C3=83=
=C2=B0=C3=A2=C2=80=C2=A2=C3=83=C2=8FX=C3=A2=C2=80=C2=9A=C3=82=C2=A2=C3=A2=
=C2=80=C2=9A=C3=82=C2=BD=C3=A2=C2=80=C2=9A=C3=82=C2=B5=C3=A2=C2=80=C2=9A=C3=
=83=C2=9C=C3=A2=C2=80=C2=9A=C3=A2=C2=80=C2=A2
> In this case, there is a definite null character, which is not legal XML,=
being=20
> sent over the wire. An Axis client receiving this response chokes in pars=
ing=20
> the XML.
> It looks like the problem may be in org.apache.axis.utils.XmlUtils. The=
=20
> xmlEncodeString() method only encodes the string if either '&', '"', '\''=
, '<'=20
> or '>' are found. If none are found, it just returns the original string =
(even=20
> if it has OTHER invalid characters) and writes it as-is.
> I've included the XmlUtils.xmlEncodeString() method below, as well as a=
=20
> suggested fix for it.
> I'm using the following:
> Implementation-Title: Apache Axis
> Implementation-Version: 1.1 1021 June 13 2003
> Implementation-Vendor: Apache Web Services
> Java: JDK 1.4.1_02
> OS: Windows XML Professional Version 2002 SP1
> CPU: Intel Xeon 3.06GHz, 1.00 GB RAM
> Any help/suggestions/recommendations would be helpful. Thanks!
> Ryan Choi
> [email protected]
> ----------------------------------------------
> Original from XmlUtils:
> public static String xmlEncodeString(String orig)
> {
> if (orig =3D=3D null)
> {
> return "";
> }
> char[] chars =3D orig.toCharArray();
> // if the string doesn't have any of the magic characters, leave
> // it alone.
> boolean needsEncoding =3D false;
> search:
> for(int i =3D 0; i < chars.length; i++) {
> switch(chars[i]) {
> case '&': case '"': case '\'': case '<': case '>':
> needsEncoding =3D true;
> break search;
> }
> }
> if (!needsEncoding) return orig;
> StringBuffer strBuf =3D new StringBuffer();
> for (int i =3D 0; i < chars.length; i++)
> {
> switch (chars[i])
> {
> case '&' : strBuf.append("&");
> break;
> case '\"' : strBuf.append(""");
> break;
> case '\'' : strBuf.append("'");
> break;
> case '<' : strBuf.append("<");
> break;
> case '\r' : strBuf.append("
");
> break;
> case '>' : strBuf.append(">");
> break;
> default :=20
> if (((int)chars[i]) > 127) {
> strBuf.append("&#");
> strBuf.append((int)chars[i]);
> strBuf.append(";");
> } else {
> strBuf.append(chars[i]);
> }
> }
> }
> return strBuf.toString();
> }
> Suggested fix for XmlUtils:
> public static String xmlEncodeString(String orig)
> {
> if (orig =3D=3D null)
> {
> return "";
> }
> char[] chars =3D orig.toCharArray();
> StringBuffer strBuf =3D new StringBuffer();
> for (int i =3D 0; i < chars.length; i++)
> {
> switch (chars[i])
> {
> case '&' : strBuf.append("&");
> break;
> case '\"' : strBuf.append(""");
> break;
> case '\'' : strBuf.append("'");
> break;
> case '<' : strBuf.append("<");
> break;
> case '\r' : strBuf.append("
");
> break;
> case '>' : strBuf.append(">");
> break;
> =09=09case '\n' : // Line Feed is OK
> =09=09case '\r' : // Carriage Return is OK
> =09=09case '\t' : // Tab is OK
> =09=09// These characters are specifically OK, as exceptions to=20
> // the general rule below:
> =09=09=09=09strBuf.append(chars[i]);
> =09=09=09=09break;
> =09=09default :
> =09=09=09if (((c >=3D 0x20) && (c <=3D 0xD7FF)) ||=20
> ((c >=3D 0xE000) && (c <=3D 0xFFFD))) {
> =09=09=09=09strBuf.append(chars[i]);
> =09=09=09}
> =09=09=09// For chars outside these ranges (such as control=20
> chars),
> =09=09=09// do nothing; it's not legal XML to print these chars,
> =09=09=09// even escaped
> }
> }
> return strBuf.toString();
> }
--=20
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: htt=
p://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira