mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 16:06:51 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user