Skip to content

Commit 6080c28

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 2733 b: refs/heads/update-datastore c: f111953 h: refs/heads/master i: 2731: aa7ceeb
1 parent 4c8a797 commit 6080c28

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
66
refs/heads/pubsub-alpha: 1a0e970f265af871e02274085b9662b3fe29058b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
8-
refs/heads/update-datastore: 8c70155e6a938d9487e4d24fdd122c31ee22113c
8+
refs/heads/update-datastore: f11195303f281414fa10b74ca402c0a99bf77313
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
1010
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2

branches/update-datastore/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

branches/update-datastore/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)