[search-documents] Fix ISO8601 date regex (#10488)

* [search-documents] Fix ISO8601 date regex (#10486)

* Add tests for dates with text before and after (#10486)
This commit is contained in:
Jacob Marshall 2020-08-10 16:13:56 +12:00 коммит произвёл GitHub
Родитель 4ad346ad77
Коммит f13a878c49
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -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{3})?Z$/i;
const GeoJSONPointTypeName = "Point";
const WorldGeodeticSystem1984 = "EPSG:4326"; // See https://epsg.io/4326

Просмотреть файл

@ -72,6 +72,24 @@ describe("serialization.deserialize", () => {
assert.deepEqual(result, { a: new Date(Date.UTC(1975, 3, 4)) });
});
it("doesn't deserialize as Date if text before", () => {
const value = "before 1975-04-04T00:00:00.000Z";
const result = deserialize({ a: value });
assert.deepEqual(result, { a: value });
});
it("doesn't deserialize as Date if text after", () => {
const value = "1975-04-04T00:00:00.000Z after";
const result = deserialize({ a: value });
assert.deepEqual(result, { a: value });
});
it("doesn't deserialize as Date if text before and after", () => {
const value = "before 1975-04-04T00:00:00.000Z after";
const result = deserialize({ a: value });
assert.deepEqual(result, { a: value });
});
it("GeographyPoint", () => {
const result: { location: GeographyPoint } = deserialize({
location: {