Skip to content

Commit cecf507

Browse files
committed
Limit incoming integers to the 32 bit signed range
Also related to #49 - unsigned integers will no longer be represented as floats. While this spec might break clients, it makes Juniper follow the GraphQL specification more closely
1 parent b673f5b commit cecf507

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/integrations/serde.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,26 @@ impl<'de> de::Deserialize<'de> for InputValue {
6767
Ok(InputValue::boolean(value))
6868
}
6969

70-
fn visit_i64<E>(self, value: i64) -> Result<InputValue, E> {
71-
Ok(InputValue::int(value))
70+
fn visit_i64<E>(self, value: i64) -> Result<InputValue, E>
71+
where E: de::Error,
72+
{
73+
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
74+
Ok(InputValue::int(value))
75+
}
76+
else {
77+
Err(E::custom(format!("integer out of range")))
78+
}
7279
}
7380

7481
fn visit_u64<E>(self, value: u64) -> Result<InputValue, E>
7582
where E: de::Error,
7683
{
77-
self.visit_f64(value as f64)
84+
if value <= i32::max_value() as u64 {
85+
self.visit_i64(value as i64)
86+
}
87+
else {
88+
Err(E::custom(format!("integer out of range")))
89+
}
7890
}
7991

8092
fn visit_f64<E>(self, value: f64) -> Result<InputValue, E> {

0 commit comments

Comments
 (0)