Resource quantity must support leading and trailing whitespace

For backwards compatibility reasons, we must continue to support leading
or trailing whitespace on Quantity values when deserialized from JSON.
This commit is contained in:
Clayton Coleman
2016-06-06 16:30:56 -04:00
parent 5c41b93d8b
commit 2ed3246631
2 changed files with 25 additions and 4 deletions

View File

@@ -259,7 +259,6 @@ Suffix:
switch str[i] {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
default:
pos = i
break Suffix
}
}
@@ -619,6 +618,7 @@ func (q Quantity) MarshalJSON() ([]byte, error) {
}
// UnmarshalJSON implements the json.Unmarshaller interface.
// TODO: Remove support for leading/trailing whitespace
func (q *Quantity) UnmarshalJSON(value []byte) error {
l := len(value)
if l == 4 && bytes.Equal(value, []byte("null")) {
@@ -633,7 +633,7 @@ func (q *Quantity) UnmarshalJSON(value []byte) error {
value = value[1 : l-1]
}
parsed, err := ParseQuantity(string(value))
parsed, err := ParseQuantity(strings.TrimSpace(string(value)))
if err != nil {
return err
}