Skip to content

Commit

Permalink
Trim whitespace from string power levels (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander authored Jan 31, 2022
1 parent 801c51a commit 8d9c3d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eventcontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (v *levelJSONValue) UnmarshalJSON(data []byte) error {
int64Value = int64(floatValue)
} else {
// If we managed to get a string, try parsing the string as an int.
int64Value, err = strconv.ParseInt(stringValue, 10, 64)
int64Value, err = strconv.ParseInt(strings.TrimSpace(stringValue), 10, 64)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion eventcontent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func BenchmarkLevelJSONValueString(b *testing.B) {

func TestLevelJSONValueValid(t *testing.T) {
var values []levelJSONValue
input := `[0,"1",2.0]`
// thanks python: https://docs.python.org/3/library/functions.html#int
// "Optionally, the literal can be preceded by + or - (with no space in between) and surrounded by whitespace."
input := `[0,"1",2.0,"+3"," +4 "]`
if err := json.Unmarshal([]byte(input), &values); err != nil {
t.Fatal("Unexpected error unmarshalling ", input, ": ", err)
}
Expand Down

0 comments on commit 8d9c3d7

Please sign in to comment.