-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: escape tabs in tag strings #111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR 👍. I have a little suggestion for replacer:
influxdb3/point.go
Outdated
// N.B. Some customers have requested support for newline and tab chars in tag values (EAR 5476) | ||
// Though this is outside the lineprotocol specification, it was supported in | ||
// previous GO client versions. | ||
tagEscapes := map[string]string{ | ||
"\n": "\\n", | ||
"\t": "\\t", | ||
} | ||
|
||
replacer := func(reps map[string]string, s string) string { | ||
result := s | ||
for key, val := range reps { | ||
result = strings.ReplaceAll(result, key, val) | ||
} | ||
return result | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you thinks about using package level Replacer
?
Something like:
var replacer = strings.NewReplacer(
"\n", "\\n",
"\t", "\\t",
)
and then use:
if value, ok := p.Values.Tags[tagKey]; ok {
enc.AddTag(tagKey, replacer.Replace(value))
} else {
enc.AddTag(tagKey, replacer.Replace(defaultTags[tagKey]))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha... I was unaware that the Replacer
type already exists in the strings
package. Updated.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #111 +/- ##
==========================================
+ Coverage 86.05% 86.12% +0.06%
==========================================
Files 15 15
Lines 1205 1211 +6
==========================================
+ Hits 1037 1043 +6
Misses 139 139
Partials 29 29 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR! 👍
LGTM 🚀
Related https://github.com/influxdata/EAR/issues/5476#issuecomment-2417071571
Proposed Changes
point.MarshallBinaryWithDefaultTags
add a mapping of strings to be escaped.TestPointWithNewLineTags
toTestPointWithEscapedTags
client_e2e_test
of tab (i.e.\t
) escapes in tags.Checklist