refactor(value): Use strconv.Quote to reveal hidden invalid characters in error messages#366
Open
refactor(value): Use strconv.Quote to reveal hidden invalid characters in error messages#366
strconv.Quote to reveal hidden invalid characters in error messages#366Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #366 +/- ##
=======================================
Coverage 73.91% 73.91%
=======================================
Files 87 87
Lines 8664 8664
=======================================
Hits 6404 6404
Misses 1700 1700
Partials 560 560 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
wenchy
requested changes
Mar 28, 2026
| return DefaultInt32Value, false, xerrors.E2000("int32", value, math.MinInt32, math.MaxInt32) | ||
| } | ||
| return pref.ValueOfInt32(int32(val)), true, xerrors.E2012("int32", value, err) | ||
| return pref.ValueOfInt32(int32(val)), true, xerrors.E2012("int32", strconv.Quote(value), err) |
Member
There was a problem hiding this comment.
NOT a good idea. Use template func instead. Make use of sprig.
For example: {{ quote .Value }} or {{ .Value | quote }}
refer to:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a cell value contains invisible or non-printable characters (e.g.,
"2000-01-01\xc2\xa005:00:00"with a non-breaking space\xc2\xa0embedded), the error message prints the value as-is, making it appear completely normal and correct to the user. This makes it extremely difficult to diagnose why the value fails to parse.Solution
Wrap values with
strconv.Quote()in error messages across allParseFieldValueparsing branches, including:int32,uint32,int64,uint64)float,double)boolgoogle.protobuf.Timestampgoogle.protobuf.DurationFraction,Comparator,Versionstrconv.Quote()produces a Go double-quoted string literal that escapes non-printable and non-ASCII bytes (e.g.,"2000-01-01\xc2\xa005:00:00"), making hidden illegal characters immediately visible in error output.Example
Before:
(looks correct — the non-breaking space is invisible)
After:
(the offending bytes
\xc2\xa0are now clearly visible)