Skip to content

Bind empty strings to nil pointers #2778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gingermusketeer
Copy link

This PR addresses an issue where empty parameter values (/?v=) are not properly handled when binding to pointer struct fields. Currently, when an empty value is passed for a field that is a pointer (e.g., *time.Time), the binding mechanism attempts to parse it rather than setting it to nil.

The change ensures that empty parameter values are treated differently from invalid values when binding to pointer fields:

  • Invalid values (e.g., /?v=x for a time.Time field) correctly return a parsing error
  • Empty values (e.g., /?v=) now properly set the pointer field to nil
  • Valid values continue to work as expected

This behavior provides a cleaner way to handle optional fields in request parameters.

The motivation behind this change is handle empty optional params as mentioned above. This behaviour seems to be the default for a number of JS clients making requests to the echo handlers.

This allows pointers to be used for optional values in query, path and
body params.
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.

1 participant