Skip to content

required check disagrees with decoding on key casing and repeated values #103

Open

Description

@ReneWerner87

The required check matches keys differently from the decoder, so a required field can be reported empty although it was decoded, or pass although it decoded to an empty value. Both came up in #100 and exist on main for every field type; map fields from #100 inherit them.

type Phone struct {
    Number string `schema:"number"`
}
type S struct {
    X     string `schema:"x,required"`
    Phone Phone  `schema:"phone,required"`
}

1. Key casing

Fields match case-insensitively, required keys only case-sensitively.

Input Decoded Error
X=v X: "v" x is empty
PHONE.number=1 Phone.Number: "1" phone is empty

DecodeValues behaves the same. directlyProvided probes src.lookup(path) and markProvidedByNestedKey probes info.requiredPrefixes[key[:off]], both exact, while the decoder resolves the field through the lowercased alias.

2. Repeated values

A scalar field takes the last of several values, but isEmpty checks value[0].

Input Decoded Error
x=&x=set X: "set" x is empty
x=set&x= X: "" none

The second case lets a required field through empty. isEmpty should check the last value for the scalar kinds.

Notes

  • The required check should stay allocation-free on the decode path; the existing benchmarks should stay flat.
  • feat: decode map fields from dotted keys #100 changes buildRequiredPrefixes, so this is easiest after it merges.
  • One test per row above, for Decode and DecodeValues.

@IslamElsayed offered to pick this up in #100.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ☢️ BugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions