Refactor to use UnsafeStringToBytes (#31358)

The PR replaces all `goldmark/util.BytesToReadOnlyString` with
`util.UnsafeBytesToString`, `goldmark/util.StringToReadOnlyBytes` with
`util.UnsafeStringToBytes`. This removes one `TODO`.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit 1761459ebc7eb6d432eced093b4583425a5c5d4b)
This commit is contained in:
Oleksandr Redko 2024-06-14 04:26:33 +03:00 committed by Earl Warren
parent b5ea092964
commit b640ac4660
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 14 additions and 18 deletions

View file

@ -8,8 +8,7 @@ import (
"code.gitea.io/gitea/models/system"
"code.gitea.io/gitea/modules/json"
"github.com/yuin/goldmark/util"
"code.gitea.io/gitea/modules/util"
)
// DBStore can be used to store app state items in local filesystem
@ -24,7 +23,7 @@ func (f *DBStore) Get(ctx context.Context, item StateItem) error {
if content == "" {
return nil
}
return json.Unmarshal(util.StringToReadOnlyBytes(content), item)
return json.Unmarshal(util.UnsafeStringToBytes(content), item)
}
// Set saves the state item
@ -33,5 +32,5 @@ func (f *DBStore) Set(ctx context.Context, item StateItem) error {
if err != nil {
return err
}
return system.SaveAppStateContent(ctx, item.Name(), util.BytesToReadOnlyString(b))
return system.SaveAppStateContent(ctx, item.Name(), util.UnsafeBytesToString(b))
}