From b9efd4019fb0e95e415f75dc3c5164a41f0c82b1 Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Fri, 9 Aug 2024 18:11:48 +0300 Subject: [PATCH 1/3] add failing test add failing test --- _fixtures/struct_tags.go | 2 +- _fixtures/struct_tags__exp.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_fixtures/struct_tags.go b/_fixtures/struct_tags.go index 3e07368..ecdaf3f 100644 --- a/_fixtures/struct_tags.go +++ b/_fixtures/struct_tags.go @@ -6,7 +6,7 @@ type MyStruct struct { Field1 string `json:"field1" info:"something"` // Field6 example adapted from https://github.com/segmentio/golines/issues/15. - ALongField2 string `json:"long_field2 ãï" info:"something else ãï" tag:"a really long tag that extends us beyond 100 chars"` + ALongField2 string `json:"long_field2 ãï" info:"something else ãï" tag:"a really long tag that extends us beyond 100 chars \\escaped\\|escaped"` Field3 string `json:"field3" info:"ãï third thing"` Field4 string `json:"field3" tag:"ãï something"` Field5 int `tag:"something else" tag:"something"` diff --git a/_fixtures/struct_tags__exp.go b/_fixtures/struct_tags__exp.go index f9e6e8d..61b5a6b 100644 --- a/_fixtures/struct_tags__exp.go +++ b/_fixtures/struct_tags__exp.go @@ -6,7 +6,7 @@ type MyStruct struct { Field1 string `json:"field1" info:"something"` // Field6 example adapted from https://github.com/segmentio/golines/issues/15. - ALongField2 string `json:"long_field2 ãï" info:"something else ãï" tag:"a really long tag that extends us beyond 100 chars"` + ALongField2 string `json:"long_field2 ãï" info:"something else ãï" tag:"a really long tag that extends us beyond 100 chars \\escaped\\|escaped"` Field3 string `json:"field3" info:"ãï third thing"` Field4 string `json:"field3" tag:"ãï something"` Field5 int ` tag:"something else"` From 684b822301002d44a3f72fba329223c8d4beb179 Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Fri, 9 Aug 2024 18:16:42 +0300 Subject: [PATCH 2/3] fix backslashes in raw literal tags --- tags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tags.go b/tags.go index 933e995..5bd4e4f 100644 --- a/tags.go +++ b/tags.go @@ -137,7 +137,7 @@ func alignTags(fields []*dst.Field) { lenUsed := 0 if ok { - tagComponents = append(tagComponents, fmt.Sprintf("%s:\"%s\"", key, value)) + tagComponents = append(tagComponents, fmt.Sprintf("%s:%#v", key, value)) lenUsed += len(key) + tagValueLen(value) + 3 } else { tagComponents = append(tagComponents, "") From 7e69c212f9124aefa5ff216a48c0dad60e10b6de Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Mon, 12 Aug 2024 02:26:02 +0300 Subject: [PATCH 3/3] change %#v to %q to clarify --- tags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tags.go b/tags.go index 5bd4e4f..4f44aa7 100644 --- a/tags.go +++ b/tags.go @@ -137,7 +137,7 @@ func alignTags(fields []*dst.Field) { lenUsed := 0 if ok { - tagComponents = append(tagComponents, fmt.Sprintf("%s:%#v", key, value)) + tagComponents = append(tagComponents, fmt.Sprintf("%s:%q", key, value)) lenUsed += len(key) + tagValueLen(value) + 3 } else { tagComponents = append(tagComponents, "")