Skip to content

Omitzero does not work with slice and map bug #1436

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

Merged

Conversation

JunaidIslam2105
Copy link
Contributor

Fixes

Fixed a bug where using omitzero still validated empty structs and maps. This PR ensures that if omitzero is used as a tag then empty slices and maps are not validated.

  • Modified the baked_in.go file to ensure that slices and maps are considered non zero only when they are not nil and they are not empty.
  • Added tests to ensure empty slices and maps are not validated while using omitzero tag.

Check #1424 for more details.

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

@JunaidIslam2105 JunaidIslam2105 requested a review from a team as a code owner June 3, 2025 18:23
@JunaidIslam2105
Copy link
Contributor Author

Hi @nodivbyzero would you kindly take a look if you get some time? Thanks

@coveralls
Copy link

Coverage Status

coverage: 73.678% (+0.004%) from 73.674%
when pulling dbe3522 on JunaidIslam2105:omitzero-slice-map-bug
into dfc7ccd on go-playground:master.

Copy link
Contributor

@nodivbyzero nodivbyzero left a comment

Choose a reason for hiding this comment

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

This looks good to me.
Thank you for making those changes.

@JunaidIslam2105
Copy link
Contributor Author

Thanks @nodivbyzero for the review. Can we merge this PR if everything looks good? Also can we work on closing issues #1424 and #1430 ?

@nodivbyzero nodivbyzero merged commit 0e3e2f9 into go-playground:master Jun 9, 2025
12 checks passed
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.

3 participants