You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by st...@apache.org on 2003/08/15 20:12:55 UTC
cvs commit: xml-axis/java/src/org/apache/axis/components/encoding AbstractXMLEncoder.java
stevel 2003/08/15 11:12:55
Modified: java/test/encoding EncodingTest.java
java/src/org/apache/axis/components/encoding
AbstractXMLEncoder.java
Log:
Retain \n \r and \t without escaping, as we have done till now. More tests. I am not sure these tests get executed, btw.
Revision Changes Path
1.2 +40 -6 xml-axis/java/test/encoding/EncodingTest.java
Index: EncodingTest.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/encoding/EncodingTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EncodingTest.java 18 Jul 2003 12:40:41 -0000 1.1
+++ EncodingTest.java 15 Aug 2003 18:12:54 -0000 1.2
@@ -25,14 +25,46 @@
try {
XMLEncoderFactory.getEncoder("XYZ");
fail("A UnsupportedEncodingException should have been thrown.");
- } catch (UnsupportedEncodingException e) {
+ } catch (UnsupportedEncodingException expected) {
// expected
}
+ assertInvalidStringsDetected(INVALID_XML_STRING);
+ //run through the first 32 chars
+ for(int i=0;i<31;i++) {
+ char c=(char)i;
+ //ignore legit whitespace
+ if ("\t\n\r".indexOf(c) == 1) {
+ //verify the others are caught
+ String s=Character.toString(c);
+ assertInvalidStringsDetected(s);
+ }
+ }
+ assertInvalidStringsDetected("foo");
+ }
+
+ /**
+ * try a string through the two encoders we have, verify it is invalid
+ * @param invalidXmlString string we expect to fail
+ * @throws Exception
+ */
+ private void assertInvalidStringsDetected(String invalidXmlString) throws Exception {
+ assertInvalidStringsDetected(XMLEncoderFactory.ENCODING_UTF_16,invalidXmlString);
+ assertInvalidStringsDetected(XMLEncoderFactory.ENCODING_UTF_8, invalidXmlString);
+ }
+
+
+
+ /**
+ * try a string through the two encoders we have, verify it is invalid
+ * @param encoderChoice name of the encoder to use
+ * @param invalidXmlString string we expect to fail
+ */
+ private void assertInvalidStringsDetected(String encoderChoice, String invalidXmlString) throws Exception {
try {
- XMLEncoder encoder = XMLEncoderFactory.getEncoder(XMLEncoderFactory.ENCODING_UTF_8);
- encoder.encode(INVALID_XML_STRING);
+ XMLEncoder encoder = XMLEncoderFactory.getEncoder(encoderChoice);
+ encoder.encode(invalidXmlString);
fail("A UnsupportedEncodingException should have been thrown.");
- } catch (IllegalArgumentException e) {
+ } catch (IllegalArgumentException expected) {
// expected
}
}
@@ -45,7 +77,8 @@
assertEquals(XMLEncoderFactory.ENCODING_UTF_8, encoder.getEncoding());
assertEquals(ENCODED_XML_SPECIAL_CHARS, encodedXMLChars);
assertEquals(GERMAN_UMLAUTS, new String(encodedUmlauts.getBytes(), XMLEncoderFactory.ENCODING_UTF_8));
- assertEquals(ENCODED_SUPPORT_CHARS_LESS_HEX_20, encoder.encode(SUPPORT_CHARS_LESS_HEX_20));
+ //assert that the whitespace chars are not touched
+ assertEquals(SUPPORT_CHARS_LESS_HEX_20, encoder.encode(SUPPORT_CHARS_LESS_HEX_20));
}
public void testUTF16() throws Exception {
@@ -58,7 +91,8 @@
assertEquals(ENCODED_XML_SPECIAL_CHARS, encodedXMLChars);
// java uses UTF-16 internally, should be equal
assertEquals(GERMAN_UMLAUTS, encodedUmlauts);
- assertEquals(ENCODED_SUPPORT_CHARS_LESS_HEX_20, encoder.encode(SUPPORT_CHARS_LESS_HEX_20));
+ //assert that the whitespace chars are not touched
+ assertEquals(SUPPORT_CHARS_LESS_HEX_20, encoder.encode(SUPPORT_CHARS_LESS_HEX_20));
}
public static void main(String[] args) {
1.2 +3 -3 xml-axis/java/src/org/apache/axis/components/encoding/AbstractXMLEncoder.java
Index: AbstractXMLEncoder.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/encoding/AbstractXMLEncoder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractXMLEncoder.java 18 Jul 2003 12:40:39 -0000 1.1
+++ AbstractXMLEncoder.java 15 Aug 2003 18:12:55 -0000 1.2
@@ -76,9 +76,9 @@
private static final byte[] QUOTE = """.getBytes();
private static final byte[] LESS = "<".getBytes();
private static final byte[] GREATER = ">".getBytes();
- private static final byte[] LF = "
".getBytes();
- private static final byte[] CR = "
".getBytes();
- private static final byte[] TAB = "	".getBytes();
+ private static final byte[] LF = "\r".getBytes();
+ private static final byte[] CR = "\n".getBytes();
+ private static final byte[] TAB = "\t".getBytes();
/**
* Encode a string