Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void sign(ClientRequest cr) {
private String getCanonicalizedResource(ClientRequest cr) {
String result = "/" + this.getAccountName();

result += cr.getURI().getPath();
result += cr.getURI().getRawPath();

List<QueryParam> queryParams = SharedKeyUtils.getQueryParams(cr.getURI().getQuery());
for (QueryParam p : queryParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -162,7 +164,17 @@ private List<String> encodeODataURIValues(List<String> values) {
}

private String getEntityPath(String table, String partitionKey, String rowKey) {
return table + "(" + "PartitionKey='" + partitionKey + "',RowKey='" + rowKey + "')";
return table + "(" + "PartitionKey='" + safeEncode(partitionKey) + "',RowKey='" + safeEncode(rowKey) + "')";
}

private String safeEncode(String input) {
String fixSingleQuotes = input.replace("'", "''");
try {
return URLEncoder.encode(fixSingleQuotes, "UTF-8").replace("+", "%20");
}
catch (UnsupportedEncodingException e) {
return fixSingleQuotes;
}
}

private WebResource addOptionalQueryParam(WebResource webResource, String key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,53 @@ public void deleteEntityWorks() throws Exception {
// Assert
}

@Test
public void deleteEntityTroublesomeKeyWorks() throws Exception {
System.out.println("deleteEntityTroublesomeKeyWorks()");

// Arrange
Configuration config = createConfiguration();
TableContract service = TableService.create(config);
Entity entity1 = new Entity().setPartitionKey("001").setRowKey("key with spaces");
Entity entity2 = new Entity().setPartitionKey("001").setRowKey("key'with'quotes");
Entity entity3 = new Entity().setPartitionKey("001").setRowKey("keyWithUnicode \uB2E4");
Entity entity4 = new Entity().setPartitionKey("001").setRowKey("key 'with'' \uB2E4");

// Act
InsertEntityResult result1 = service.insertEntity(TEST_TABLE_2, entity1);
InsertEntityResult result2 = service.insertEntity(TEST_TABLE_2, entity2);
InsertEntityResult result3 = service.insertEntity(TEST_TABLE_2, entity3);
InsertEntityResult result4 = service.insertEntity(TEST_TABLE_2, entity4);

service.deleteEntity(TEST_TABLE_2, result1.getEntity().getPartitionKey(), result1.getEntity().getRowKey());
service.deleteEntity(TEST_TABLE_2, result2.getEntity().getPartitionKey(), result2.getEntity().getRowKey());
service.deleteEntity(TEST_TABLE_2, result3.getEntity().getPartitionKey(), result3.getEntity().getRowKey());
service.deleteEntity(TEST_TABLE_2, result4.getEntity().getPartitionKey(), result4.getEntity().getRowKey());

// Assert

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to assert the success of the deletion by validating the original entities do not exist any more?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll add that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below for the new asserts

try {
service.getEntity(TEST_TABLE_2, result1.getEntity().getPartitionKey(), result1.getEntity().getRowKey());
assertFalse("Expect an exception when getting an entity that does not exist", true);
}
catch (ServiceException e) {
assertEquals("expect getHttpStatusCode", 404, e.getHttpStatusCode());

}

QueryEntitiesResult assertResult2 = service.queryEntities(
TEST_TABLE_2,
new QueryEntitiesOptions().setQuery(new Query().setFilter(Filter.eq(Filter.litteral("RowKey"),
Filter.constant("key'with'quotes")))));

assertEquals(0, assertResult2.getEntities().size());

QueryEntitiesResult assertResult3 = service.queryEntities(TEST_TABLE_2);
for (Entity entity : assertResult3.getEntities()) {
assertFalse("Entity3 should be removed from the table", entity3.getRowKey().equals(entity.getRowKey()));
assertFalse("Entity4 should be removed from the table", entity4.getRowKey().equals(entity.getRowKey()));
}
}

@Test
public void deleteEntityWithETagWorks() throws Exception {
System.out.println("deleteEntityWithETagWorks()");
Expand Down