-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Cannot unmarshal struct when key is not English #413
Labels
bug
Something isn't working
Comments
artemklevtsov
changed the title
Cannot unmarshal struct when key is
Cannot unmarshal struct when key is not English
Nov 30, 2022
The root cause of this issue is that the tag name is strings.ToLower for case insensitive lookup of field names in the structure, but the decoding process only looks up from the largeToSmallTable and does not consider the locale. https://go.dev/play/p/xRsK6qvU3XJ Code: var (
largeToSmallTable [256]byte
)
func init() {
for i := 0; i < 256; i++ {
c := i
if 'A' <= c && c <= 'Z' {
c += 'a' - 'A'
}
largeToSmallTable[i] = byte(c)
}
}
func toLower(s string) string {
var b []byte
for _, c := range []byte(s) {
b = append(b, largeToSmallTable[c])
}
return string(b)
}
func main() {
s := "Сообщение"
fmt.Println(toLower(s))
fmt.Println(strings.ToLower(s))
} Output:
@goccy How do we correct the problem? |
orisano
added a commit
to orisano/go-json
that referenced
this issue
Feb 24, 2023
orisano
added a commit
to orisano/go-json
that referenced
this issue
Feb 24, 2023
orisano
added a commit
to orisano/go-json
that referenced
this issue
Mar 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems realted with #234.
Exptected
Actual
The text was updated successfully, but these errors were encountered: