Skip to content

Commit f111953

Browse files
author
Ajay Kannan
committed
remove check for valid utf-8 cursor
1 parent 8c70155 commit f111953

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Cursor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.api.services.datastore.DatastoreV1.Value;
2424
import com.google.common.base.MoreObjects;
2525
import com.google.common.base.MoreObjects.ToStringHelper;
26-
import com.google.common.base.Preconditions;
2726
import com.google.protobuf.ByteString;
2827
import com.google.protobuf.InvalidProtocolBufferException;
2928
import com.google.protobuf.TextFormat;
@@ -44,7 +43,6 @@ public final class Cursor extends Serializable<DatastoreV1.Value> {
4443
private final transient ByteString byteString;
4544

4645
Cursor(ByteString byteString) {
47-
Preconditions.checkArgument(byteString.isValidUtf8(), "content is not a valid UTF-8");
4846
this.byteString = byteString;
4947
}
5048

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.google.gcloud.datastore.testing.LocalGcdHelper;
4040
import com.google.gcloud.spi.DatastoreRpc;
4141
import com.google.gcloud.spi.DatastoreRpcFactory;
42+
import com.google.protobuf.ByteString;
4243

4344
import org.easymock.EasyMock;
4445
import org.junit.AfterClass;
@@ -496,7 +497,7 @@ public void testQueryPaginationWithLimit() throws DatastoreException {
496497
}
497498
query = query.toBuilder().startCursor(results.cursorAfter()).build();
498499
}
499-
assertEquals(totalCount, 5);
500+
assertEquals(5, totalCount);
500501
EasyMock.verify(rpcFactoryMock, rpcMock);
501502
}
502503

@@ -524,7 +525,8 @@ private List<RunQueryResponse> buildResponsesForQueryPaginationWithLimit() {
524525
.setMoreResults(QueryResultBatch.MoreResultsType.MORE_RESULTS_AFTER_LIMIT)
525526
.clearEntityResult()
526527
.addAllEntityResult(queryResultBatchPb.getEntityResultList().subList(1, 2))
527-
.setEndCursor(queryResultBatchPb.getEntityResultList().get(1).getCursor())
528+
.setEndCursor(
529+
ByteString.copyFrom(new byte[] {(byte) 0x80})) // test invalid UTF-8 string
528530
.build();
529531
responses.add(RunQueryResponse.newBuilder().setBatch(queryResultBatchPb2).build());
530532
QueryResultBatch queryResultBatchPb3 = QueryResultBatch.newBuilder()
@@ -546,6 +548,17 @@ private List<RunQueryResponse> buildResponsesForQueryPaginationWithLimit() {
546548
return responses;
547549
}
548550

551+
@Test
552+
public void testToUrlSafe() {
553+
byte[][] invalidUtf8 =
554+
new byte[][] {{(byte) 0xfe}, {(byte) 0xc1, (byte) 0xbf}, {(byte) 0xc0}, {(byte) 0x80}};
555+
for (byte[] bytes : invalidUtf8) {
556+
assertFalse(ByteString.copyFrom(bytes).isValidUtf8());
557+
Cursor cursor = new Cursor(ByteString.copyFrom(bytes));
558+
assertEquals(cursor, Cursor.fromUrlSafe(cursor.toUrlSafe()));
559+
}
560+
}
561+
549562
@Test
550563
public void testAllocateId() {
551564
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND1);

0 commit comments

Comments
 (0)