Repository navigation
fix: do not traverse struct fields if type has parser or implements TextUnmarshaler (#440) - #445
webdevsamran wants to merge 2 commits into
Conversation
…extUnmarshaler (caarlos0#440) Signed-off-by: Samran Asif <samranwebdev2000@gmail.com>
SiluPanda
left a comment
There was a problem hiding this comment.
Thanks for addressing the parser-versus-struct traversal boundary. go test ./... passed on this head.
I also ran an additional local case with UseFieldNameByDefault and RequiredIfNoDef enabled: preinitialized and nil *url.URL fields, []url.URL, and a custom pointer-receiver TextUnmarshaler used as a value, pointer, and slice element. With conflicting HOST/PATH variables present, all of those retained their parsed values.
A small, non-blocking coverage suggestion: could one custom TextUnmarshaler case be included in the committed tests? The new test name mentions that path, but its field is currently only url.URL. No blocker found in the behavior I checked.
AI-assisted review using Codex; the local checks above were executed.
…RLAndTextUnmarshaler Signed-off-by: Samran Asif <samranwebdev2000@gmail.com>
|
Thanks @SiluPanda! Added a custom pointer-receiver TextUnmarshaler test case (covering both value and pointer fields) to TestUseFieldNameByDefault_URLAndTextUnmarshaler in commit 57149ea. All tests pass cleanly. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #445 +/- ##
===========================================
- Coverage 100.00% 99.77% -0.23%
===========================================
Files 3 3
Lines 427 435 +8
===========================================
+ Hits 427 434 +7
- Misses 0 1 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
caarlos0
left a comment
There was a problem hiding this comment.
Bot review by GitHub Copilot.
No findings. Reviewed the complete diff at 57149ea484a27d472e9593dc6cf8a545f3e8e7fe against merge base fb6403538040f91bb1d4e3fac6c55905ebd10b2d, with the relevant parsing logic, callers, documentation, and tests. Both independent checks completed: a read-only maintainer check and a verify-only adversarial check. The primary reviewer independently traced the relevant code paths.
All 29 focused tests passed, including the new regression tests and existing parser, error, pointer initialization, indexed slice, prefix, default, and field-parameter cases.
Verification limits: No standalone build, full suite, race run, or cross-platform validation was performed. The baseline overwrite behavior was inspected, not reproduced against the base commit. Preinitialized parser-backed pointers and parser-backed slices with conflicting indexed variables under UseFieldNameByDefault were inspected, but no targeted regressions were executed for those combinations.
|
lint is failing though |
Summary
When
UseFieldNameByDefaultis enabled, struct fields that have a custom type parser or implementencoding.TextUnmarshaler(such asurl.URLortime.Location) had their internal fields (Host,Path, etc.) traversed bydoParse. This caused environment variables matching internal struct field names (such asPATHorHOST) to overwrite parsed values or fail validation ifRequiredIfNoDefwas set (#440).hasCustomOrTextParserTypehelper to check if a struct type has a parser registered inopts.FuncMap(includingdefaultTypeParsers) or implementsencoding.TextUnmarshaler.doParseFieldwhenhasCustomOrTextParserTypeis true.isSliceOfStructsto avoid treating slices of custom-parsed struct types (such as[]url.URL) as index-prefixed struct collections.env_test.goverifying thaturl.URLretains its parsed values and does not get overwritten byHOSTorPATH.Closes #440
AI assistance disclosure: Authored with AI assistance (Google Antigravity); changes and tests independently reviewed and verified locally.