From 7c5ab2ee835c5bc87c7ec797a175b3c541d06bd1 Mon Sep 17 00:00:00 2001 From: kostyay Date: Thu, 15 Dec 2022 13:38:30 +0200 Subject: [PATCH 1/2] Always escape values in comments as per specification --- go/core/core.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/go/core/core.go b/go/core/core.go index 6fca682a..da4c2420 100644 --- a/go/core/core.go +++ b/go/core/core.go @@ -57,7 +57,7 @@ type CommenterOptions struct { } func encodeURL(k string) string { - return url.QueryEscape(string(k)) + return url.QueryEscape(k) } func GetFunctionName(i interface{}) string { @@ -71,7 +71,7 @@ func ConvertMapToComment(tags map[string]string) string { var sb strings.Builder i, sz := 0, len(tags) - //sort by keys + // sort by keys sortedKeys := make([]string, 0, len(tags)) for k := range tags { sortedKeys = append(sortedKeys, k) @@ -80,9 +80,9 @@ func ConvertMapToComment(tags map[string]string) string { for _, key := range sortedKeys { if i == sz-1 { - sb.WriteString(fmt.Sprintf("%s=%v", encodeURL(key), encodeURL(tags[key]))) + sb.WriteString(fmt.Sprintf("%s=%s", encodeURL(key), encodeURL(tags[key]))) } else { - sb.WriteString(fmt.Sprintf("%s=%v,", encodeURL(key), encodeURL(tags[key]))) + sb.WriteString(fmt.Sprintf("%s=%s,", encodeURL(key), encodeURL(tags[key]))) } i++ } From 3dc25a4a3c52992f737c54d284d35d346b41e2b4 Mon Sep 17 00:00:00 2001 From: kostyay Date: Thu, 15 Dec 2022 14:03:39 +0200 Subject: [PATCH 2/2] escape --- go/core/core.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/core/core.go b/go/core/core.go index da4c2420..c2d30696 100644 --- a/go/core/core.go +++ b/go/core/core.go @@ -80,9 +80,9 @@ func ConvertMapToComment(tags map[string]string) string { for _, key := range sortedKeys { if i == sz-1 { - sb.WriteString(fmt.Sprintf("%s=%s", encodeURL(key), encodeURL(tags[key]))) + sb.WriteString(fmt.Sprintf("%s='%s'", encodeURL(key), encodeURL(tags[key]))) } else { - sb.WriteString(fmt.Sprintf("%s=%s,", encodeURL(key), encodeURL(tags[key]))) + sb.WriteString(fmt.Sprintf("%s='%s',", encodeURL(key), encodeURL(tags[key]))) } i++ }