Skip to content

Commit 605a062

Browse files
committed
Fixed BSONTest.testUTF8 to ignore surrogate characters, which are not valid UTF-8 characters, so that the test passes on Java 8.
1 parent 443b684 commit 605a062

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/test/org/bson/BSONTest.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,22 @@ public void testOBBig1(){
161161
}
162162

163163
@Test
164-
public void testUTF8(){
165-
for ( int i=1; i<=Character.MAX_CODE_POINT; i++ ){
166-
167-
if ( ! Character.isValidCodePoint( i ) )
164+
public void testUTF8() {
165+
for (int i = 1; i <= Character.MAX_CODE_POINT; i++) {
166+
167+
if (!Character.isValidCodePoint(i)) {
168168
continue;
169-
170-
String orig = new String( Character.toChars( i ) );
171-
BSONObject a = new BasicBSONObject( orig , orig );
172-
BSONObject b = BSON.decode( BSON.encode( a ) );
173-
assertEquals( a , b );
174-
}
169+
}
175170

171+
if (Character.isSurrogate((char) i)) {
172+
continue;
173+
}
174+
175+
String orig = new String(Character.toChars(i));
176+
BSONObject a = new BasicBSONObject(orig, orig);
177+
BSONObject b = BSON.decode(BSON.encode(a));
178+
assertEquals(a, b);
179+
}
176180
}
177181

178182
@Test

0 commit comments

Comments
 (0)