From jbossws-commits at lists.jboss.org Wed Mar 10 12:50:02 2010 Content-Type: multipart/mixed; boundary="===============2062427326153415057==" MIME-Version: 1.0 From: jbossws-commits at lists.jboss.org To: jbossws-commits at lists.jboss.org Subject: [jbossws-commits] JBossWS SVN: r11751 - in common/trunk/src: test/java/org/jboss/test/ws/common and 1 other directory. Date: Wed, 10 Mar 2010 12:50:02 -0500 Message-ID: <201003101750.o2AHo2TQ007553@svn01.web.mwc.hst.phx2.redhat.com> --===============2062427326153415057== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: darran.lofthouse(a)jboss.com Date: 2010-03-10 12:50:01 -0500 (Wed, 10 Mar 2010) New Revision: 11751 Added: common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCase.j= ava Modified: common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java Log: [JBWS-2885] CDATA Responses Being Incorrectly Escaped. Modified: common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java 2010-03= -10 17:27:01 UTC (rev 11750) +++ common/trunk/src/main/java/org/jboss/wsf/common/Normalizer.java 2010-03= -10 17:50:01 UTC (rev 11751) @@ -28,13 +28,18 @@ * * @author Martin Vecera * @author Alessio Soldano +* @author Darran Lofthouse= +* = * @since 09-Dic-2009 -* = */ final public class Normalizer { private static final Pattern PATTERN =3D Pattern.compile("[&<>'\"\r\n]"= ); = + private static final String CDATA_START =3D ""; + public static String normalize(String strValue) { return normalize(strValue, false); @@ -45,11 +50,57 @@ Matcher m =3D PATTERN.matcher(strValue); if (m.find()) { + int len =3D strValue.length(); + StringBuilder sb =3D new StringBuilder(len * 3); // faster than S= tringBuffer, not thread safe + int start =3D 0; + + while (start < len) + { + int cdataStart =3D strValue.indexOf(CDATA_START, start); + if (cdataStart > -1) + { + int cdataEnd =3D strValue.indexOf(CDATA_END, cdataStart); + // If a valid start and end to a section are + // identified exclude from normalisation. = + if (cdataEnd > -1) + { + if (cdataStart > start) + { + normalize(strValue.substring(start, cdataStart), cano= nical, sb); + } + sb.append(strValue.subSequence(cdataStart, cdataEnd + 3)= ); + start =3D cdataEnd + 3; + } + else + { + normalize(strValue.substring(start, len), canonical, sb); + start =3D len; + } + } + else + { + normalize(strValue.substring(start, len), canonical, sb); + start =3D len; + } + } + + return sb.toString(); + } + else + { + return strValue; + } + } + + private static void normalize(String strValue, boolean canonical, Strin= gBuilder sb) + { + Matcher m =3D PATTERN.matcher(strValue); + if (m.find()) + { int pos =3D m.start(); // we can use previous match to skip some = part at the string beginning int len =3D strValue.length(); // just a single call to length() char[] input =3D new char[len]; // this is to ommit calls to Stri= ng.charAt() strValue.getChars(0, len, input, 0); - StringBuilder sb =3D new StringBuilder(len * 3); // faster than S= tringBuffer, not thread safe = int copyStart =3D 0; = @@ -119,12 +170,10 @@ { sb.append(input, copyStart, len - copyStart); } - - return sb.toString(); } else { - return strValue; + sb.append(strValue); } } } Added: common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCa= se.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCase.= java (rev 0) +++ common/trunk/src/test/java/org/jboss/test/ws/common/NormalizerTestCase.= java 2010-03-10 17:50:01 UTC (rev 11751) @@ -0,0 +1,104 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2010, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.test.ws.common; + +import org.jboss.wsf.common.Normalizer; + +import junit.framework.TestCase; + +/** + * [JBWS-2885] http://jira.jboss.com/jira/browse/JBWS-2885 + * = + * Test case to test sections are skipped in the = + * normalization process. + * = + * @author darran.lofthouse(a)jboss.com + * @since Mar 10, 2010 + */ +public class NormalizerTestCase extends TestCase +{ + + private static final String CDATA_STRING =3D ""; + + public void testCDATAOnly() + { + String normalized =3D Normalizer.normalize(CDATA_STRING); + + assertEquals("Normalized String", CDATA_STRING, normalized); + } + + public void testCDATABegin() + { + String normalized =3D Normalizer.normalize(CDATA_STRING + "ABC"); + + assertEquals("Normalized String", CDATA_STRING + "ABC", normalized); + } + + public void testCDATAEnd() + { + String normalized =3D Normalizer.normalize("ABD" + CDATA_STRING); + + assertEquals("Normalized String", "ABD" + CDATA_STRING, normalized); + } + + public void testCDATAMid() + { + String normalized =3D Normalizer.normalize("ABD" + CDATA_STRING + "E= FG"); + + assertEquals("Normalized String", "ABD" + CDATA_STRING + "EFG", norm= alized); + } + + public void testCDATADouble() + { + String normalized =3D Normalizer.normalize("ABD" + CDATA_STRING + "E= FG" + CDATA_STRING + "HIJ"); + + assertEquals("Normalized String", "ABD" + CDATA_STRING + "EFG" + CDA= TA_STRING + "HIJ", normalized); + } + = + public void testCDATABegin_Replace() + { + String normalized =3D Normalizer.normalize(CDATA_STRING + "<>"); + + assertEquals("Normalized String", CDATA_STRING + "<>", normali= zed); + } + + public void testCDATAEnd_Replace() + { + String normalized =3D Normalizer.normalize("<>" + CDATA_STRING); + + assertEquals("Normalized String", "<>" + CDATA_STRING, normali= zed); + } + + public void testCDATAMid_Replace() + { + String normalized =3D Normalizer.normalize("<>" + CDATA_STRING + "<>= "); + + assertEquals("Normalized String", "<>" + CDATA_STRING + "<&= gt;", normalized); + } + + public void testCDATADouble_Replace() + { + String normalized =3D Normalizer.normalize("<>" + CDATA_STRING + "<>= " + CDATA_STRING + "<>"); + + assertEquals("Normalized String", "<>" + CDATA_STRING + "<&= gt;" + CDATA_STRING + "<>", normalized); + } +} Property changes on: common/trunk/src/test/java/org/jboss/test/ws/common/No= rmalizerTestCase.java ___________________________________________________________________ Name: svn:keywords + Id Revision Name: svn:eol-style + LF --===============2062427326153415057==--