-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
opts: parseKeyValueFile: cleanup and remove redundant trimming #5496
Conversation
thaJeztah
commented
Oct 3, 2024
- relates to introduce ParseKeyValueFile #5491
- the function already trimmed leading whitespace from each line before parsing. keys with trailing whitespace would be invalidated, and values have whitespace preserved, so there's no need to trim whitespace for the key.
- if a line is validated (key is valid), we don't need to reconstruct the key=value by concatenating, and we can add the line as-is.
- check if the key is empty before checking if it contains whitespace
- touch-up comments
- rename some variables for readability
- slight cleanup to use early returns / early continues to reduce nesting
I'll rebase #5491 after this; still looking at separating this to a separate package, so there will be some follow-ups. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5496 +/- ##
==========================================
- Coverage 60.09% 60.09% -0.01%
==========================================
Files 345 345
Lines 23445 23441 -4
==========================================
- Hits 14090 14086 -4
Misses 8381 8381
Partials 974 974 |
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.
LGTM (plus bikeshedding!).
// leading whitespace was already removed from the line, but | ||
// variables are not allowed to contain whitespace or have | ||
// trailing whitespace. | ||
if strings.ContainsAny(key, whiteSpaces) { |
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.
It seems odd to search for whitespace like this, but trim leading whitespace with TrimLeftFunc(_, unicode.IsSpace)
above?
strings.ContainsFunc(key, unicode.IsSpace)
would catch things that were missed before (like non-breaking space), so I guess it'd be a breaking change. Maybe worthwhile though?
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.
Yeah, I was looking at that as well; indeed also considering whether we should change. I'll keep this one for a follow-up in the meantime, but good suggestion.
bd9ff60
to
355b18f
Compare
- the function already trimmed leading whitespace from each line before parsing. keys with trailing whitespace would be invalidated, and values have whitespace preserved, so there's no need to trim whitespace for the key. - if a line is validated (key is valid), we don't need to reconstruct the key=value by concatenating, and we can add the line as-is. - check if the key is empty before checking if it contains whitespace - touch-up comments - rename some variables for readability - slight cleanup to use early returns / early continues to reduce nesting Signed-off-by: Sebastiaan van Stijn <[email protected]>
355b18f
to
76196db
Compare