From bbd62af4f4096572db15fed66fda446ecc2e35da Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 29 Feb 2024 10:31:23 -0800 Subject: [PATCH 1/2] Don't error on empty time value Exit early if the value is empty. --- sdk/data/aztables/CHANGELOG.md | 1 + sdk/data/aztables/autorest.md | 10 +++++++++- sdk/data/aztables/internal/zz_time_rfc1123.go | 3 +++ sdk/data/aztables/internal/zz_time_rfc3339.go | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sdk/data/aztables/CHANGELOG.md b/sdk/data/aztables/CHANGELOG.md index 44276d10008f..2ac497ca9df3 100644 --- a/sdk/data/aztables/CHANGELOG.md +++ b/sdk/data/aztables/CHANGELOG.md @@ -12,6 +12,7 @@ ### Bugs Fixed * Fixed an issue that could cause `Client.NewListEntitiesPager` to skip pages in some cases. +* Fixed an issue that could cause unmarshaling empty time values to fail. ### Other Changes diff --git a/sdk/data/aztables/autorest.md b/sdk/data/aztables/autorest.md index cdfda8c8b550..35b81dbd55cf 100644 --- a/sdk/data/aztables/autorest.md +++ b/sdk/data/aztables/autorest.md @@ -21,7 +21,7 @@ modelerfour: seal-single-value-enum-by-default: true directive: - - from: source-file-go + - from: zz_table_client.go where: $ transform: >- return $. @@ -34,6 +34,14 @@ directive: replace(/= client\.mergeEntityCreateRequest\(/, `= client.MergeEntityCreateRequest(`). replace(/= client\.updateEntityCreateRequest\(/, `= client.UpdateEntityCreateRequest(`). replace(/if rowKey == "" \{\s*.*\s*\}\s*/g, ``); + - from: + - zz_time_rfc1123.go + where: $ + transform: return $.replace(/UnmarshalText\(data\s+\[\]byte\)\s+error\s+\{\s/g, `UnmarshalText(data []byte) error {\n\tif len(data) == 0 {\n\t\treturn nil\n\t}\n`); + - from: + - zz_time_rfc3339.go + where: $ + transform: return $.replace(/UnmarshalText\(data\s+\[\]byte\)\s+\(error\)\s+\{\s/g, `UnmarshalText(data []byte) error {\n\tif len(data) == 0 {\n\t\treturn nil\n\t}\n`); ``` ### Go multi-api diff --git a/sdk/data/aztables/internal/zz_time_rfc1123.go b/sdk/data/aztables/internal/zz_time_rfc1123.go index 39577c893718..3d4e0f8135c1 100644 --- a/sdk/data/aztables/internal/zz_time_rfc1123.go +++ b/sdk/data/aztables/internal/zz_time_rfc1123.go @@ -36,6 +36,9 @@ func (t *dateTimeRFC1123) UnmarshalJSON(data []byte) error { } func (t *dateTimeRFC1123) UnmarshalText(data []byte) error { + if len(data) == 0 { + return nil + } p, err := time.Parse(time.RFC1123, string(data)) *t = dateTimeRFC1123(p) return err diff --git a/sdk/data/aztables/internal/zz_time_rfc3339.go b/sdk/data/aztables/internal/zz_time_rfc3339.go index 511119b93a7b..96c08aad5019 100644 --- a/sdk/data/aztables/internal/zz_time_rfc3339.go +++ b/sdk/data/aztables/internal/zz_time_rfc3339.go @@ -44,6 +44,9 @@ func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { } func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + if len(data) == 0 { + return nil + } layout := utcDateTime if tzOffsetRegex.Match(data) { layout = time.RFC3339Nano From 4b6faecc15b68e820f5cf6473b35c4bfc6a06136 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 29 Feb 2024 10:38:02 -0800 Subject: [PATCH 2/2] improve regex to avoid duplication --- sdk/data/aztables/autorest.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sdk/data/aztables/autorest.md b/sdk/data/aztables/autorest.md index 35b81dbd55cf..32e5a1a13132 100644 --- a/sdk/data/aztables/autorest.md +++ b/sdk/data/aztables/autorest.md @@ -36,12 +36,9 @@ directive: replace(/if rowKey == "" \{\s*.*\s*\}\s*/g, ``); - from: - zz_time_rfc1123.go - where: $ - transform: return $.replace(/UnmarshalText\(data\s+\[\]byte\)\s+error\s+\{\s/g, `UnmarshalText(data []byte) error {\n\tif len(data) == 0 {\n\t\treturn nil\n\t}\n`); - - from: - zz_time_rfc3339.go where: $ - transform: return $.replace(/UnmarshalText\(data\s+\[\]byte\)\s+\(error\)\s+\{\s/g, `UnmarshalText(data []byte) error {\n\tif len(data) == 0 {\n\t\treturn nil\n\t}\n`); + transform: return $.replace(/UnmarshalText\(data\s+\[\]byte\)\s+(?:error|\(error\))\s+\{\s/g, `UnmarshalText(data []byte) error {\n\tif len(data) == 0 {\n\t\treturn nil\n\t}\n`); ``` ### Go multi-api