Skip to content

Commit 3e0621d

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1603 b: refs/heads/master c: f111953 h: refs/heads/master i: 1601: 6c03146 1599: 4e85956
1 parent 6fe1eec commit 3e0621d

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
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8c70155e6a938d9487e4d24fdd122c31ee22113c
2+
refs/heads/master: f11195303f281414fa10b74ca402c0a99bf77313
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: d1b373c30c176edc08692348167bec3a244bb823
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3

trunk/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

trunk/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)