-
-
Notifications
You must be signed in to change notification settings - Fork 195
Treat output from TextMarshaler as string #698
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
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.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #698 +/- ##
==========================================
+ Coverage 77.89% 77.92% +0.03%
==========================================
Files 22 22
Lines 7965 7965
==========================================
+ Hits 6204 6207 +3
+ Misses 1348 1346 -2
+ Partials 413 412 -1 🚀 New features to boost your workflow:
|
@@ -400,20 +400,21 @@ func (e *Encoder) encodeByMarshaler(ctx context.Context, v reflect.Value, column | |||
if t, ok := iface.(time.Time); ok { | |||
return e.encodeTime(t, column), nil | |||
} | |||
// Handle *time.Time explicitly since it implements TextMarshaler and shouldn't be treated as plain text | |||
if t, ok := iface.(*time.Time); ok && t != nil { |
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.
This works correctly 👍
Since isInvalidValue
becomes true at the beginning of encodeValue
when *time.Time is nil, this process is always executed only when *time.Time is not nil.
Thank you for your great PR ! LGTM 👍 |
…65] (#708) ## Summary Pinned the `go-yaml` version until goccy/go-yaml#698 is released. ## Release Notes Fixes segmentation violation errors when `apiVersion` was set to an empty string in any of the v1alpha objects.
Closes #689.
The original issue was that since
null.StringFrom
implements theTextMarshaler
interface,goccy/go-yaml
tries to interpret its output as a YAML document usinge.encodeDocument
. However, because the output contains a special character (in this case,#
), the parser fails to handle it correctly and returnsnil
.IIUC, the output from a
TextMarshaler
implementation should not be interpreted as a YAML document. It should be treated as a plain string, sinceTextMarshaler
is intended to return a textual representation of a value. This behavior is consistent withgopkg.in/yaml.v3
.One side effect I noticed after making this change is related to how
*time.Time
is encoded. Previously, since*time.Time
also implementsTextMarshaler
, it was being encoded by the code block below. After treating the output fromMarshalText()
as a string, the library started wrapping*time.Time
values in double quotes. To prevent this, I updated theencodeByMarshaler
function to handle*time.Time
explicitly.