Skip to content
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

Fix accessing fields in composed structs #733

Merged

Conversation

Adimus11
Copy link
Contributor

Fixes Or Enhances

This change fixes the issue with validating fields in composed structures when the validator uses . before the composed struct in the parent one.

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/admins

@coveralls
Copy link

coveralls commented Feb 25, 2021

Coverage Status

Coverage increased (+0.004%) to 76.074% when pulling d6c143c on Adimus11:correctlly-validate-composed-structs into f6584a4 on go-playground:master.

@@ -409,7 +409,10 @@ func (v *Validate) StructPartialCtx(ctx context.Context, s interface{}, fields .
if len(flds) > 0 {

vd.misc = append(vd.misc[0:0], name...)
vd.misc = append(vd.misc, '.')
// Don't append empty name for composed structs
if string(vd.misc) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check the length of vd.misc here instead of casting to a string? It would be one less allocation :)

@deankarn deankarn merged commit ec1baac into go-playground:master Apr 6, 2021
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.

None yet

3 participants