Skip to content

Commit

Permalink
[Search] Fix ISO8601 deserialization (Azure#25801)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgetu authored and minhanh-phan committed Jun 12, 2023
1 parent b3c8dd5 commit 0d3798f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions sdk/search/search-documents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- `SearchRequestOptions`
- `SuggestRequest`
- Fix discarded user-defined `onResponse` callback [#24479](https://github.com/Azure/azure-sdk-for-js/pull/24479)
- Fix ISO8601 deserialization [#25801](https://github.com/Azure/azure-sdk-for-js/pull/25801)

### Other Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/search/search-documents/src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import GeographyPoint from "./geographyPoint";

const ISO8601DateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/i;
const ISO8601DateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/i;
const GeoJSONPointTypeName = "Point";
const WorldGeodeticSystem1984 = "EPSG:4326"; // See https://epsg.io/4326

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ describe("serialization.deserialize", function () {
assert.deepEqual(result, { a: new Date(Date.UTC(1975, 3, 4)) });
});

it("Date with truncated ms field", function () {
const result = deserialize({ a: "1975-04-04T00:00:00.0Z" });
assert.deepEqual(result, { a: new Date(Date.UTC(1975, 3, 4)) });
});

it("doesn't deserialize as Date if text before", function () {
const value = "before 1975-04-04T00:00:00.000Z";
const result = deserialize({ a: value });
Expand Down

0 comments on commit 0d3798f

Please sign in to comment.