Skip to content

Commit b1f8a77

Browse files
authored
test: fix serde proptests (#742)
Proptests in automaton serde where not properly guarding for arbitrary generated queries being too complex and exceeding the automaton size limit.
1 parent f372a34 commit b1f8a77

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

crates/rsonpath-lib/src/engine/serde.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ mod tests {
163163
}
164164
}
165165

166-
let automaton = Automaton::new(&parsed)?;
166+
let automaton = match Automaton::new(&parsed) {
167+
Ok(x) => Ok(x),
168+
Err(crate::automaton::error::CompilerError::QueryTooComplex(_)) => Err(TestCaseError::Reject("query too complex".into())),
169+
Err(e) => Err(e.into()),
170+
}?;
167171
let engine = RsonpathEngine::from_compiled_query(automaton.clone());
168172

169173
let mut buf = vec![];
@@ -182,7 +186,11 @@ mod tests {
182186
..Default::default()
183187
}
184188
)) {
185-
let automaton = Automaton::new(&parsed)?;
189+
let automaton = match Automaton::new(&parsed) {
190+
Ok(x) => Ok(x),
191+
Err(crate::automaton::error::CompilerError::QueryTooComplex(_)) => Err(TestCaseError::Reject("query too complex".into())),
192+
Err(e) => Err(e.into()),
193+
}?;
186194
let engine = RsonpathEngine::from_compiled_query(automaton.clone());
187195

188196
let json_str = serde_json::to_string(&engine)?;
@@ -198,7 +206,11 @@ mod tests {
198206
..Default::default()
199207
}
200208
)) {
201-
let automaton = Automaton::new(&parsed)?;
209+
let automaton = match Automaton::new(&parsed) {
210+
Ok(x) => Ok(x),
211+
Err(crate::automaton::error::CompilerError::QueryTooComplex(_)) => Err(TestCaseError::Reject("query too complex".into())),
212+
Err(e) => Err(e.into()),
213+
}?;
202214
let engine = RsonpathEngine::from_compiled_query(automaton.clone());
203215

204216
let buf = rmp_serde::to_vec(&engine)?;

0 commit comments

Comments
 (0)