Skip to content
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

Merged
merged 4 commits into from
Oct 18, 2024
Merged

feat: escape tabs in tag strings #111

merged 4 commits into from
Oct 18, 2024

Conversation

karel-rehor
Copy link
Contributor

@karel-rehor karel-rehor commented Oct 17, 2024

Related https://github.com/influxdata/EAR/issues/5476#issuecomment-2417071571

Proposed Changes

  • In point.MarshallBinaryWithDefaultTags add a mapping of strings to be escaped.
  • In same method add an internal method for iterating over map and escaping values in source string
  • Rename TestPointWithNewLineTags to TestPointWithEscapedTags
  • Add check in this and in client_e2e_test of tab (i.e. \t) escapes in tags.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

Copy link
Member

@bednar bednar left a 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:

Comment on lines 251 to 265
// 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
}
Copy link
Member

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]))
		}

Copy link
Contributor Author

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.

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.12%. Comparing base (7989828) to head (33c78a2).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@karel-rehor karel-rehor requested a review from bednar October 17, 2024 12:18
Copy link
Member

@bednar bednar left a 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 🚀

@karel-rehor karel-rehor merged commit 86c45d7 into main Oct 18, 2024
13 checks passed
@karel-rehor karel-rehor deleted the feat/escapeTagTabs branch October 18, 2024 08:34
@bednar bednar added this to the 0.14.0 milestone Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants