Skip to content

Commit

Permalink
Fix merge entity fail with pk/rk contains single quota (#2009) (#2024)
Browse files Browse the repository at this point in the history
* Fix merge entity fail with pk/rk contains single quota (#2009)

* temp: remove test case
  • Loading branch information
blueww authored Jun 30, 2023
1 parent f846265 commit 99e1947
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Table:

- Fixed issue with query table fail with filter condition as string.Empty. (issue #1880)
- Fixed merge table entity fail with single quota in PK/RK. (issue #2009)

## 2023.06 Version 3.24.0

Expand Down
17 changes: 5 additions & 12 deletions src/table/middleware/tableStorageContext.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,11 @@ export function tableStorageContextMiddleware(
0,
tableSection.indexOf("(")
);
const firstQuoteIndex = tableSection.indexOf("'");
const secondQuoteIndex = tableSection.indexOf("'", firstQuoteIndex + 1);
const thridQuoteIndex = tableSection.indexOf("'", secondQuoteIndex + 1);
const fourthQuoteIndex = tableSection.indexOf("'", thridQuoteIndex + 1);
tableContext.partitionKey = tableSection.substring(
firstQuoteIndex + 1,
secondQuoteIndex
);
tableContext.rowKey = tableSection.substring(
thridQuoteIndex + 1,
fourthQuoteIndex
);

const regex = /'([^']|'')*'/g;
const matches = tableSection?.match(regex);
tableContext.partitionKey = matches? matches[0].replace(/^'|'$/g, '').replace(/''/g, "'"): undefined;
tableContext.rowKey = matches? matches[1].replace(/^'|'$/g, '').replace(/''/g, "'"): undefined;

tableSection = `${tableContext.tableName}(PartitionKey='PLACEHOLDER',RowKey='PLACEHOLDER')`;
} else if (
Expand Down
55 changes: 55 additions & 0 deletions tests/table/apis/table.entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1608,4 +1608,59 @@ describe("table Entity APIs test - using Azure-Storage", () => {
});
});
});

it("36. Merge on an Entity with single quota in PartitionKey and RowKey, @loki", (done) => {
const partitionKey = "pk single'quota string";
const rowKey= "rk single'quota string";

// Insert entity with the specific pk,rk
const entityInsert = new TestEntity(partitionKey, rowKey, "value1");
tableService.insertEntity(
tableName,
entityInsert,
(insertError, insertResult, insertresponse) => {
if (insertError) {
assert.fail(insertError.message);
done();
}
else
{
// merge entity with the specific pk,rk, to a different value
const entityMerge = new TestEntity(partitionKey, rowKey, "value2");
tableService.mergeEntity(
tableName,
entityMerge,
(mergeError, updateResult, updateResponse) => {
if (!mergeError) {
assert.strictEqual(updateResponse.statusCode, 204); // Precondition succeeded

// retrieve entity with the specific pk,rk, and validate value is updated
tableService.retrieveEntity<TestEntity>(
tableName,
partitionKey,
rowKey,
(error, result) => {
if (error) {
assert.fail(error.message);
done();
}
else
{
assert.strictEqual(result.PartitionKey._, partitionKey);
assert.strictEqual(result.RowKey._, rowKey);
assert.strictEqual(result.myValue._, "value2");
done();
}
}
);
} else {
assert.fail(mergeError.message);
done();
}
}
);
}
}
);
});
});

0 comments on commit 99e1947

Please sign in to comment.