Skip to content

Commit

Permalink
Insert check for whitespace surrounding numeric map key
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 11, 2023
1 parent defa896 commit 9f4c4af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.disable_recursion_limit = true;
}

fn peek(&mut self) -> Result<Option<u8>> {
pub(crate) fn peek(&mut self) -> Result<Option<u8>> {
self.read.peek()
}

Expand Down
14 changes: 12 additions & 2 deletions src/value/de.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::Error;
use crate::error::{Error, ErrorCode};
use crate::map::Map;
use crate::number::Number;
use crate::value::Value;
Expand Down Expand Up @@ -1131,8 +1131,18 @@ macro_rules! deserialize_numeric_key {
V: Visitor<'de>,
{
let mut de = crate::Deserializer::from_str(&self.key);

match tri!(de.peek()) {
Some(b'0'..=b'9' | b'-') => {}
_ => return Err(Error::syntax(ErrorCode::ExpectedNumericKey, 0, 0)),
}

let number = tri!(de.$using(visitor));
tri!(de.end());

if tri!(de.peek()).is_some() {
return Err(Error::syntax(ErrorCode::ExpectedNumericKey, 0, 0));
}

Ok(number)
}
};
Expand Down

0 comments on commit 9f4c4af

Please sign in to comment.