Skip to content

Fix false-positive omitempty detection in JSON struct tags - #610

Merged
k8s-ci-robot merged 1 commit into
kubernetes:masterfrom
arthurbdiniz:fix-omitempty-false-positive
May 12, 2026
Merged

k8s-ci-robot merged 1 commit into
kubernetes:masterfrom
arthurbdiniz:fix-omitempty-false-positive

Conversation

@arthurbdiniz

Copy link
Copy Markdown
Contributor

The existing strings.Contains(tag, "omitempty") checks match the substring anywhere in the JSON tag value, causing false positives for field names like json:"omitemptyTest" or json:"fooOmitempty".

This PR introduces a hasOmitemptyTag helper that correctly identifies omitempty as a comma-delimited option.

Introduce a hasOmitemptyTag helper that treats "omitempty" as a
comma-delimited option rather than an arbitrary substring.

Signed-off-by: Arthur Diniz <arthurbd@debian.org>
@k8s-ci-robot
k8s-ci-robot requested review from Jefftree and sttts May 12, 2026 19:53
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 12, 2026
@arthurbdiniz

Copy link
Copy Markdown
Contributor Author

/cc @liggitt

@k8s-ci-robot
k8s-ci-robot requested a review from liggitt May 12, 2026 19:56
@liggitt

liggitt commented May 12, 2026

Copy link
Copy Markdown
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 12, 2026
@jpbetz

jpbetz commented May 12, 2026

Copy link
Copy Markdown
Contributor

/approve

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arthurbdiniz, jpbetz, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 12, 2026
@k8s-ci-robot
k8s-ci-robot merged commit d58ecf2 into kubernetes:master May 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants