diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-05-09 10:36:17 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-05-09 10:41:15 +0200 |
commit | 4b4d2c25b473eb09db661215941ff88bcb49589c (patch) | |
tree | ebbad72deb4c16c4b57fcd380d09dc90c83f6243 | |
parent | 2362aa34cd7409ba02fc5f42e4e07bd318530275 (diff) |
Add OOB-error checking in array case
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/resolver.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/resolver.rs b/src/resolver.rs index acbaeb6..6c61020 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -51,6 +51,14 @@ pub fn resolve<'doc, O>(obj: &'doc O, tokens: &Token, error_if_not_found: bool) match tokens { Token::Index { idx, .. } => { trace!("Checking object at index {}", idx); + if !obj.has_index(*idx) { + if let Some(len) = obj.array_len() { + return Err(Error::IndexOutOfBounds(*idx, len)); + } else { + return Err(Error::IndexOutOfBounds(*idx, 0)); + } + } + match tokens.next() { Some(next) => { trace!("There is another token..."); @@ -661,7 +669,7 @@ mod test { .unwrap(); let result = do_resolve!(toml => "example.foo.[1]"); - assert!(result.is_err()); + assert!(result.is_err(), format!("Error expected but having: {:?}", result)); let result = result.unwrap_err(); assert!(is_match!(result, Error::IndexOutOfBounds { .. })); |