Skip to content

fix(conversions): clean []map[any]any slices and add URLValuesSliceKeySuffix getter - #193

Open
mazkev wants to merge 1 commit into
stretchr:masterfrom
mazkev:fix/clean-interface-map-slice
Open

mazkev wants to merge 1 commit into
stretchr:masterfrom
mazkev:fix/clean-interface-map-slice

Conversation

@mazkev

@mazkev mazkev commented Oct 30, 2026

Copy link
Copy Markdown

Summary

  1. Clean []map[any]any slices before JSON encoding:

    • cleanUp(v any) previously supported []any, []map[string]any, []Map, and map[any]any, but omitted []map[any]any (slices of interface maps commonly produced by YAML unmarshalers or dynamic data).
    • Because concrete slice types do not match []any in Go type switches, []map[any]any fell through to default: return v, resulting in json: unsupported type: map[interface {}]interface {} when calling JSON() or Base64().
    • Added cleanUpInterfaceMapArray(in []map[any]any) []Map and registered case []map[any]any: in cleanUp.
  2. Add URLValuesSliceKeySuffix getter:

    • The doc comment in conversions.go previously referenced an exported URLValuesSliceKeySuffix variable, which was replaced by an unexported variable and SetURLValuesSliceKeySuffix(s string).
    • Added URLValuesSliceKeySuffix() string to allow callers and tests to inspect and safely restore previous suffixes without hardcoding default constants.
  3. Tests:

    • Added unit test cases for nil, empty, and populated []map[any]any in conversions_nil_test.go and conversions_test.go.
    • Tested URLValuesSliceKeySuffix() getter alongside SetURLValuesSliceKeySuffix.
    • Verified that all unit tests pass (go test -v ./...).

@hanzei hanzei left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

Can you please explain why URLValuesSliceKeySuffix needs to be exported? What value does it add for callers?

@mazkev

mazkev commented Oct 30, 2026

Copy link
Copy Markdown
Author

Hi @hanzei, thanks for the review!

The motivation for adding the URLValuesSliceKeySuffix() getter was twofold:

  1. Safe configuration restore / inspection: Since SetURLValuesSliceKeySuffix mutates package-level global state, callers (and tests) currently have no way to inspect the active suffix or temporarily change it and restore the previous state without hardcoding the default constant (e.g. defer SetURLValuesSliceKeySuffix(URLValuesSliceKeySuffix())).
  2. Documentation alignment: The doc comment on lines 17-23 historically referenced URLValuesSliceKeySuffix, which was formerly an exported variable before being made private with a setter.

That being said, if you prefer keeping the public API surface minimal and not exposing the getter, I am more than happy to remove URLValuesSliceKeySuffix() from this PR and keep only the []map[any]any slice cleanup fix!

Let me know what you prefer and I can update the branch accordingly.

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