Skip to content

Commit

Permalink
Fail the insert entity request with double property whose value is gr…
Browse files Browse the repository at this point in the history
…eater than MAX_VALUE (Issue #2387) (#2388)

* Fail the insert entity request with double property whose value is greater than MAX_VALUE (Issue #2387)

* Fix a typo

* Add more accurate value in test and comments
  • Loading branch information
blueww authored Apr 16, 2024
1 parent 0e6b520 commit ad3114c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Blob:
- Fix HTTP header parsing of `SubmitBatch()`. If a HTTP header has HTTP header delimiter (`:`) in its value, `SubmitBatch()` returns "400 One of the request inputs is not valid". For example, if `user-agent` header is `azsdk-cpp-storage-blobs/12.10.0-beta.1 (Darwin 23.1.0 arm64 Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:12 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8103)`, all `SubmitBatch()` requests are failed.
- Fixed issue of blob copying succeed without 'r' permission in source blob's SAS token credential.

Table:

- Fail the insert entity request with double property whose value is greater than MAX_VALUE (Issue #2387)

## 2023.12 Version 3.29.0

General:
Expand Down
5 changes: 5 additions & 0 deletions src/table/entity/EdmDouble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export class EdmDouble implements IEdmType {
// TODO: Support convert from string. parseFloat doesn't strictly checks non number chars
const val = Number.parseFloat(value);
if (!Number.isNaN(val)) {
// Test on both Product server and Azurite, they are aligned: "1.797693134862315e308" will pass validation, "1.797693134862316e308" will fail validation.
if (val === Number.POSITIVE_INFINITY || val === Number.NEGATIVE_INFINITY)
{
throw TypeError(`InvalidInput`);
}
return val;
}
}
Expand Down
64 changes: 64 additions & 0 deletions tests/table/apis/table.entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1726,4 +1726,68 @@ describe("table Entity APIs test - using Azure-Storage", () => {
}
);
});


// For github issue 2387
// Insert entity property with type "Edm.Double" and value bigger than MAX_VALUE, server will fail the request
it("38. Insert entity with Edm.Double type property whose value is bigger than MAX_VALUE, server will fail the request, @loki", (done) => {
// Double value bigger than MAX_VALUE will fail
const entity1 = {
PartitionKey: "partDouble",
RowKey: "utctestDouble",
myValue: "1.797693134862316e308",
"[email protected]": "Edm.Double"
};

tableService.insertEntity(
tableName,
entity1,
(insertError, insertResult, insertResponse) => {
if (!insertError) {
assert.fail(
"Insert should fail with Edm.Double type property whose value is greater than MAX_VALUE.");
} else {
assert.strictEqual(
true,
insertError.message.startsWith(
"An error occurred while processing this request."
)
);
};
assert.strictEqual("InvalidInput", (insertError as any).code);
}
);

// Double value smaller than MAX_VALUE will success
const entity2 = {
PartitionKey: "partDouble",
RowKey: "utctestDouble",
myValue: "1.797693134862315e308",
"[email protected]": "Edm.Double"
};

tableService.insertEntity(
tableName,
entity2,
(insertError, insertResult, insertResponse) => {
if (!insertError) {
tableService.retrieveEntity<TestEntity>(
tableName,
"partDouble",
"utctestDouble",
(error, result) => {
const insertedEntity: TestEntity = result;
assert.strictEqual(
insertedEntity.myValue._.toString(),
"1.797693134862315e+308"
);
done();
}
);
} else {
assert.fail(
"Insert should NOT fail with Edm.Double type property whose value is less than MAX_VALUE.");
}
});
});
});

0 comments on commit ad3114c

Please sign in to comment.