Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search] Fix ISO8601 deserialization #25801

Merged
merged 3 commits into from
May 9, 2023
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
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