schema: improve errors, disallow dangling spaces.

This commit is contained in:
fiatjaf
2025-11-20 10:45:37 -03:00
parent a62ddd1326
commit 4cbca27104
2 changed files with 80 additions and 23 deletions

25
schema/helpers.go Normal file
View File

@@ -0,0 +1,25 @@
package schema
import (
"unicode"
"unicode/utf8"
)
// isTrimmed checks if strings.TrimSpace(v) == v, i.e. that the value doesn't have dangling spaces
func isTrimmed(s string) bool {
if len(s) == 0 {
return true
}
first, _ := utf8.DecodeRuneInString(s)
if unicode.IsSpace(first) {
return false
}
last, _ := utf8.DecodeLastRuneInString(s)
if unicode.IsSpace(last) {
return false
}
return true
}