From 9d1ab2c8a184f7f208a543b8ee471ae5eaf19e0d Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 18 Oct 2021 16:40:54 +0800 Subject: [PATCH] Add test for parsing overflow. --- tests/stack.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/stack.rs b/tests/stack.rs index 527522bf..febdcbbd 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -46,13 +46,39 @@ fn test_stack_overflow_parsing() -> Result<(), Box> { ParseErrorType::ExprTooDeep ); + engine.compile("1 + 2")?; + + #[cfg(debug_assertions)] + engine.compile( + " + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + ", + )?; + + #[cfg(debug_assertions)] + assert_eq!( + *engine + .compile( + " + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + + 1 + " + ) + .expect_err("should error") + .0, + ParseErrorType::ExprTooDeep + ); + engine.set_max_expr_depths( 100, #[cfg(not(feature = "no_function"))] 6, ); - engine.compile("1 + 2")?; engine.compile( " 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 +