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

JSON tag uses "omitempty" as the field name #33660

Closed
Vasco-jofra opened this issue Feb 20, 2025 · 0 comments · Fixed by #33663
Closed

JSON tag uses "omitempty" as the field name #33660

Vasco-jofra opened this issue Feb 20, 2025 · 0 comments · Fixed by #33663
Labels
Milestone

Comments

@Vasco-jofra
Copy link

Description

Hi! While doing a broad search for this pattern, I noticed that you use "omitempty" as the name of a structure field.

Args []any `json:"omitempty"`

Instead, I believe you intended to use ",omitempty" to keep the default name and add the omitempty option.

You can test this behavior with this simple Go program. As you can see by the result, the omitempty key in the JSON string gets unmarshaled to the field with the json:"omitempty" tag.

package main

import (
	"encoding/json"
	"fmt"
)

type SomeStruct struct {
	SomeField string `json:"omitempty"`
}

func main() {
	u := SomeStruct{}
	_ = json.Unmarshal([]byte(`{"omitempty": "123"}`), &u)
	fmt.Printf("Result: %#v\n", u)
	// Result: main.SomeStruct{SomeField:"123"}
}

Gitea Version

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Database

None

@lunny lunny added this to the 1.23.5 milestone Feb 20, 2025
lunny added a commit that referenced this issue Feb 20, 2025
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Feb 21, 2025
lunny added a commit that referenced this issue Feb 21, 2025
Backport #33663 by @lunny

Fix #33660

Co-authored-by: Lunny Xiao <[email protected]>
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants