Repository navigation
Keep v1 behavior for struct fields read from keys and allowshadow slices - #437
Merged
Merged
Conversation
MapTo leaves a struct field unchanged when only a key of its name exists, as v1 did, so programs that parse such a key themselves (frp's legacy bandwidth_limit) keep working. StrictMapTo still reports it. ReflectFrom writes an allowshadow slice of several elements as one value joined by the delimiter when the file has no AllowShadows, instead of failing. It reads back as all elements; v1 wrote only the first.
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.
Describe the pull request
An audit of 37 projects that import go-ini directly found two v2 struct-mapping changes that break real users. Neither is in the migration guide. This PR goes back to v1's results in both cases, but keeps v2's guarantees: strict mode still reports the problem, and no data is dropped.
1.
MapTowith a struct field whose name matches only a key. A struct field maps to a section. When no section of that name exists but a key does, v2 returnedunsupported type. v1 skipped the field. frp relies on that: its legacy proxy config hasBandwidthLimit types.BandwidthQuantity \ini:"bandwidth_limit"`, whichdecorate()parses afterMapTo. Under v2, every legacy config withbandwidth_limit` failed to load.The fix treats this like any other value that doesn't fit its field.
MapToleaves the field unchanged and keeps mapping the other fields.StrictMapToreturns an error. Slices of structs read from a key are still an error, as before.2.
ReflectFromwith anallowshadowslice of several elements, on a file withoutAllowShadows. v1 wrote only the first element, silently. v2 returnedshadow key is not allowed, which makes nginx-ui's settings migration (ReflectFromintoini.Empty()) exit fatally. v2 now writes the elements as one value joined by the delimiter. The decoder already splitsallowshadowvalues at the delimiter, so this value reads back as every element, with or withoutAllowShadows. The existing check that no element contains the delimiter still applies. Files loaded withAllowShadowsstill get one line per element.Both behaviours were deliberate in #425, so the PR updates
TestMapTo_StructFieldsFromKeysandTestReflectFrom_AllowShadowinstead of adding new tests. Both tests fail onmainand pass with this change. The migration guide gets a line for theallowshadowchange. The struct-field case needs no line, because it now matches v1.Link to the issue: n/a
Checklist
AI usage
Written by Amp (an AI coding agent) at the maintainer's request, following a v1/v2 differential audit against downstream importers. Validation:
go test ./...,go vet, 45 s ofFuzzStructMapping, and side-by-side reproductions of the frp and nginx-ui cases against v1.67.x and this branch.