5
5
6
6
import java .io .ByteArrayOutputStream ;
7
7
8
- public class TestSaxWriter extends base .BaseTestCase {
9
-
10
- public void testSurrogateMemory1 () throws Exception {
8
+ public class TestSaxWriter extends base .BaseTestCase
9
+ {
10
+ public void testSplitSurrogateWithAttributeValue () throws Exception
11
+ {
11
12
// This test aims to produce the
12
13
// javax.xml.stream.XMLStreamException: Incomplete surrogate pair in content: first char 0xd835, second 0x78
13
14
// error message. Before fixing the respective issue, it was provoked by a multi-byte character
@@ -16,12 +17,13 @@ public void testSurrogateMemory1() throws Exception {
16
17
// of the original multi-byte character with the first character in the third buffer because
17
18
// ByteXmlWriter#_surrogate was not set back to 0 after writing the original multi-byte character.
18
19
StringBuilder testText = new StringBuilder ();
19
- for (int i = 0 ; i < 511 ; i ++)
20
+ for (int i = 0 ; i < 511 ; i ++) {
20
21
testText .append ('x' );
22
+ }
21
23
testText .append ("\uD835 \uDFCE " );
22
- for (int i = 0 ; i < 512 ; i ++)
24
+ for (int i = 0 ; i < 512 ; i ++) {
23
25
testText .append ('x' );
24
-
26
+ }
25
27
WriterConfig writerConfig = new WriterConfig ();
26
28
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
27
29
Utf8XmlWriter writer = new Utf8XmlWriter (writerConfig , byteArrayOutputStream );
@@ -30,19 +32,20 @@ public void testSurrogateMemory1() throws Exception {
30
32
writer .writeStartTagEnd ();
31
33
writer .writeEndTag (writer .constructName ("testelement" ));
32
34
writer .close (false );
33
-
34
35
}
35
36
36
- public void testSurrogateMemory2 () throws Exception {
37
+ public void testSplitSurrogateWithAttributeValue2 () throws Exception
38
+ {
37
39
// This test aims to produce the
38
40
// java.io.IOException: Unpaired surrogate character (0xd835)
39
41
// error message. Before fixing the respective issue, it was provoked by a multi-byte character
40
42
// where the first byte was exactly at the end of the internal reading buffer and the next
41
43
// reading buffer was enough to write all the remaining data. Then, by the missing reset of
42
44
// ByteXmlWriter#_surrogate, the code expected another multi-byte surrogate that never came.
43
45
StringBuilder testText = new StringBuilder ();
44
- for (int i = 0 ; i < 511 ; i ++)
46
+ for (int i = 0 ; i < 511 ; i ++) {
45
47
testText .append ('x' );
48
+ }
46
49
testText .append ("\uD835 \uDFCE " );
47
50
48
51
WriterConfig writerConfig = new WriterConfig ();
@@ -55,18 +58,21 @@ public void testSurrogateMemory2() throws Exception {
55
58
writer .close (false );
56
59
}
57
60
58
- public void testSurrogateMemory3 () throws Exception {
61
+ public void testSplitSurrogateWithCData () throws Exception
62
+ {
59
63
// This test aims to produce the
60
64
// javax.xml.stream.XMLStreamException: Incomplete surrogate pair in content: first char 0xdfce, second 0x78
61
65
// error message. The issue was similar to the one described in testSurrogateMemory1(), except it happened in
62
66
// ByteXmlWriter#writeCDataContents(), where check for existing _surrogate was missing prior to the fix,
63
67
// as opposed to ByteXmlWriter#writeCharacters().
64
68
StringBuilder testText = new StringBuilder ();
65
- for (int i = 0 ; i < 511 ; i ++)
69
+ for (int i = 0 ; i < 511 ; i ++) {
66
70
testText .append ('x' );
71
+ }
67
72
testText .append ("\uD835 \uDFCE " );
68
- for (int i = 0 ; i < 512 ; i ++)
73
+ for (int i = 0 ; i < 512 ; i ++) {
69
74
testText .append ('x' );
75
+ }
70
76
71
77
WriterConfig writerConfig = new WriterConfig ();
72
78
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
@@ -76,7 +82,5 @@ public void testSurrogateMemory3() throws Exception {
76
82
writer .writeStartTagEnd ();
77
83
writer .writeEndTag (writer .constructName ("testelement" ));
78
84
writer .close (false );
79
-
80
85
}
81
-
82
86
}
0 commit comments