Skip to content

Commit

Permalink
Since JsonBuffer is reading character-by-character anyway, there is n…
Browse files Browse the repository at this point in the history
…o need to use String.codePointAt. And doing so is incorrect

unless there is a corresponding call to Character.charCount instead of just incrementing the position by a single character.  The fix
is simply to use use String.charAt instead of String.codePointAt.

 JAVA-1793
  • Loading branch information
jyemin committed May 4, 2015
1 parent 0663d73 commit 49654cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bson/src/main/org/bson/json/JsonBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public void setPosition(final int position) {
}

public int read() {
return (position >= buffer.length()) ? -1 : buffer.codePointAt(position++);
return (position >= buffer.length()) ? -1 : buffer.charAt(position++);
}

public void unread(final int c) {
if (c != -1 && buffer.codePointAt(position - 1) == c) {
if (c != -1 && buffer.charAt(position - 1) == c) {
position--;
}
}
Expand Down
26 changes: 24 additions & 2 deletions bson/src/test/unit/org/bson/json/JsonReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,32 @@ public void testRegularExpressionStrict() {

@Test
public void testString() {
String json = "\"abc\"";
String str = "abc";
String json = '"' + str + '"';
bsonReader = new JsonReader(json);
assertEquals(BsonType.STRING, bsonReader.readBsonType());
assertEquals("abc", bsonReader.readString());
assertEquals(str, bsonReader.readString());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());

str = "\ud806\udc5c";
json = '"' + str + '"';
bsonReader = new JsonReader(json);
assertEquals(BsonType.STRING, bsonReader.readBsonType());
assertEquals(str, bsonReader.readString());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());

str = "\\ud806\\udc5c";
json = '"' + str + '"';
bsonReader = new JsonReader(json);
assertEquals(BsonType.STRING, bsonReader.readBsonType());
assertEquals("\ud806\udc5c", bsonReader.readString());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());

str = "꼢𑡜ᳫ鉠鮻罖᧭䆔瘉";
json = '"' + str + '"';
bsonReader = new JsonReader(json);
assertEquals(BsonType.STRING, bsonReader.readBsonType());
assertEquals(str, bsonReader.readString());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
}

Expand Down

0 comments on commit 49654cf

Please sign in to comment.