diff --git a/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java b/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java index 0b3e4e4..9599059 100644 --- a/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java +++ b/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java @@ -204,8 +204,9 @@ boolean isHighSurrogate = false; for (int i = 0; i < readByte; i++) { ch = buf[i]; - if (ch < 0x20 && ch != 0x9 && ch != 0xA && ch != 0xD) { - //Unicode characters in the range 0x0000-0x001F other than 9, A, and D are not allowed in XML + if (ch < 0x20 && ch != 0x9 && ch != 0xA && ch != 0xD && ch != 0x0) { + //Unicode characters in the range 0x0000-0x001F other than 9, A, and D are not allowed in XML + //We need to allow the NULL character, however, for Flash XMLSocket clients to work. throw new Exception("Disallowed character"); } if (isHighSurrogate) { diff --git a/test/org/jivesoftware/multiplexer/net/XMLLightweightParserTest.java b/test/org/jivesoftware/multiplexer/net/XMLLightweightParserTest.java index ccd6271..8be7ee7 100644 --- a/test/org/jivesoftware/multiplexer/net/XMLLightweightParserTest.java +++ b/test/org/jivesoftware/multiplexer/net/XMLLightweightParserTest.java @@ -298,6 +298,30 @@ } } + public void testAllowNullChars() throws Exception { + byte[] one = ("").getBytes(); + byte[] two = {(byte) 0x0}; + byte[] three = "".getBytes(); + + byte[] message = new byte[one.length + two.length + three.length]; + int j = 0; + for (byte b : one) { + message[j++] = b; + } + for (byte b : two) { + message[j++] = b; + } + for (byte b : three) { + message[j++] = b; + } + + ByteBuffer mybuffer = ByteBuffer.wrap(message); + parser.read(mybuffer); + String[] stanzas = parser.getMsgs(); + assertEquals("Incorrect number of stanzas parsed", 1, stanzas.length); + assertEquals("Incorrect stanza parsed", "\u0000", stanzas[0]); + } + public void testInvalidSurrogates() throws Exception { byte[] one = ("").getBytes(); byte[] two = {(byte) 0xed, (byte) 0xb3, (byte) 0xb1};