Skip to content

refactor(value): Use strconv.Quote to reveal hidden invalid characters in error messages#366

Open
Kybxd wants to merge 2 commits intomasterfrom
quote-invalid-values
Open

refactor(value): Use strconv.Quote to reveal hidden invalid characters in error messages#366
Kybxd wants to merge 2 commits intomasterfrom
quote-invalid-values

Conversation

@Kybxd
Copy link
Copy Markdown
Collaborator

@Kybxd Kybxd commented Mar 17, 2026

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\xa0 embedded), 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 all ParseFieldValue parsing branches, including:

  • Integer types (int32, uint32, int64, uint64)
  • Floating-point types (float, double)
  • bool
  • google.protobuf.Timestamp
  • google.protobuf.Duration
  • Well-known types: Fraction, Comparator, Version

strconv.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:

failed to parse value "2000-01-01 05:00:00" as google.protobuf.Timestamp

(looks correct — the non-breaking space is invisible)

After:

failed to parse value "2000-01-01\xc2\xa005:00:00" as google.protobuf.Timestamp

(the offending bytes \xc2\xa0 are now clearly visible)

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.91%. Comparing base (bc70718) to head (d813ed9).

Files with missing lines Patch % Lines
internal/x/xproto/value.go 66.66% 6 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOT a good idea. Use template func instead. Make use of sprig.

For example: {{ quote .Value }} or {{ .Value | quote }}

refer to:

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