Repository navigation
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
I traced the new scalar gate against current doParseField semantics and I think the type-level check is a little too broad. |
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
The external report was independently reproduced: RED expected nested Rule: scalar-capable structs use the parser only when that field has its own key/default; keyless prefixed pointers recurse. Focused/full |
caarlos0
left a comment
There was a problem hiding this comment.
Bot review. Requesting changes for one reproduced parsing regression. No local build or full test suite was run.
| scalar := isScalarStruct(refField.Type(), opts.FuncMap) && | ||
| (params.OwnKey != "" || params.HasDefaultValue) |
There was a problem hiding this comment.
[P2] Preserve prefixed containers when field names are inferred
With UseFieldNameByDefault: true, parseFieldParams generates OwnKey == "NESTED" for an initialized Nested *scalar field tagged only with envPrefix:"NESTED_". If scalar has a registered FuncMap parser, this condition therefore treats the field as a scalar and skips the nested-container path, even when only NESTED_VALUE is supplied.
I ran the same production-API reproduction against the merge base and this head: the base loads NESTED_VALUE successfully, but this head returns nil and leaves the old nested value unchanged. With RequiredIfNoDef: true, it instead reports that NESTED is missing, although the required child value is present.
Preserve container traversal for explicit prefix-only fields whose key comes solely from automatic field naming, honoring PrefixTagName; retain scalar handling for explicit keys/defaults and scalar fields without a container prefix. Extend TestParseCustomScalarStructAsNestedContainer with UseFieldNameByDefault: true and both values of RequiredIfNoDef, supplying only the prefixed child variable and asserting successful parsing of the child.
Fixes #440
Problem
With
UseFieldNameByDefault, scalar structs such asurl.URLwere recursively parsed a second time after the tagged value had already been decoded. This letHOSTandPATHoverwrite URL internals, and madeRequiredIfNoDefdemand exported implementation fields.Fix
Avoid recursive parsing when the field type has already been handled by a scalar parser.
RED evidence
url.URLbecamehttp://evil/usr/binbecauseHOSTandPATHoverwroteHostandPath.RequiredIfNoDefdemanded internalurl.URLfields such asSCHEME,OPAQUE, andHOST.Verification
go test ./... -count=1go test -race -shuffle=on -count=1 ./...go build ./...go vet ./...Scope
Two files: parser logic and regression tests.