diff options
Diffstat (limited to 'src')
-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 { .. })); |