Skip to content

Commit 81b3bae

Browse files
committed
Add support for Bareword token in expression parsing and enhance tests for QUERY_STRING evaluation
1 parent f403a7d commit 81b3bae

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

esi/src/expression.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ fn parse_expr(cur: &mut Peekable<Iter<Token>>) -> Result<Expr> {
343343
match token {
344344
Token::Integer(i) => Expr::Integer(*i),
345345
Token::String(s) => Expr::String(s.clone()),
346+
Token::Bareword(s) => Expr::String(s.clone()),
346347
Token::Dollar => parse_dollar(cur)?,
347348
unexpected => {
348349
return Err(ExecutionError::ExpressionError(format!(
@@ -1132,6 +1133,17 @@ mod tests {
11321133
Ok(())
11331134
}
11341135
#[test]
1136+
fn test_eval_get_request_query_field_unquoted() -> Result<()> {
1137+
let mut ctx = EvalContext::new();
1138+
ctx.set_request(Request::new(Method::GET, "http://localhost?hello=goodbye"));
1139+
1140+
let result = evaluate_expression("$(QUERY_STRING{hello})", &mut ctx)?;
1141+
assert_eq!(result, Value::Text("goodbye".into()));
1142+
let result = evaluate_expression("$(QUERY_STRING{nonexistent})", &mut ctx)?;
1143+
assert_eq!(result, Value::Null);
1144+
Ok(())
1145+
}
1146+
#[test]
11351147
fn test_eval_get_remote_addr() -> Result<()> {
11361148
// This is kind of a useless test as this will always return an empty string.
11371149
let mut ctx = EvalContext::new();

0 commit comments

Comments
 (0)