https://github.com/go-gitea/gitea/pull/29395 (cherry picked from commit e71b69257c38178eed9ccd0b62a5ae47d67858d4)