mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Metadata: Sanitize bad Unicode strings #2897
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
21
pkg/clean/unicode.go
Normal file
21
pkg/clean/unicode.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package clean
|
||||
|
||||
import "strings"
|
||||
|
||||
// Unicode returns a string a valid unicode.
|
||||
func Unicode(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
|
||||
for _, c := range s {
|
||||
if c == '\uFFFD' {
|
||||
continue
|
||||
}
|
||||
b.WriteRune(c)
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
Reference in New Issue
Block a user