Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
mitigates #360 (for numeric strings)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trolldemorted committed Jul 4, 2017
1 parent a941737 commit 621a447
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,29 @@ macro_rules! messages {
});
}

let id = ls_command.get("id").and_then(|id| id.as_u64()).map(|id| id as usize);

let id: Option<usize> = match ls_command.get("id") {
Some(v) => {
if v.is_u64() {
Some(v.as_u64().unwrap() as usize)
} else if v.is_string() {
match usize::from_str_radix(v.as_str().unwrap(), 10) {
Ok(v) => Some(v),
Err(_) => None
}
} else {
None
}
},
None => None
};
if let Some(v) = ls_command.get("method") {
if let Some(name) = v.as_str() {
match name {
$(
$method_str => {
match id {
Some(id) => Ok(ServerMessage::Request(Request{id, method: Method::$method_name$((params_as!($method_arg)))* })),
None => Err(ParseError::new(ErrorKind::InvalidData, "id is not an integer", None)),
None => Err(ParseError::new(ErrorKind::InvalidData, "Id is not a number or numeric string", None)),
}
}
)*
Expand Down

0 comments on commit 621a447

Please sign in to comment.