forked from Rust-related/RustPython
fix panic OpMinUntil return before restore repeat
This commit is contained in:
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug Unit Test",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run"
|
||||
],
|
||||
"filter": {
|
||||
"kind": "test"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -14,7 +14,7 @@ pub struct State<'a> {
|
||||
pub string: StrDrive<'a>,
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
flags: SreFlag,
|
||||
_flags: SreFlag,
|
||||
pattern_codes: &'a [u32],
|
||||
pub marks: Vec<Option<usize>>,
|
||||
pub lastindex: isize,
|
||||
@@ -42,7 +42,7 @@ impl<'a> State<'a> {
|
||||
string,
|
||||
start,
|
||||
end,
|
||||
flags,
|
||||
_flags: flags,
|
||||
pattern_codes,
|
||||
lastindex: -1,
|
||||
marks_stack: Vec::new(),
|
||||
@@ -1380,16 +1380,18 @@ impl OpcodeExecutor for OpMinUntil {
|
||||
None
|
||||
}
|
||||
2 => {
|
||||
// restore repeat before return
|
||||
drive.state.repeat_stack.push(self.save_repeat.unwrap());
|
||||
|
||||
let child_ctx = drive.state.popped_context.unwrap();
|
||||
if child_ctx.has_matched == Some(true) {
|
||||
drive.ctx_mut().has_matched = Some(true);
|
||||
return None;
|
||||
}
|
||||
drive.state.repeat_stack.push(self.save_repeat.unwrap());
|
||||
drive.state.string_position = drive.ctx().string_position;
|
||||
drive.state.marks_pop();
|
||||
|
||||
// match more unital tail matches
|
||||
// match more until tail matches
|
||||
let RepeatContext {
|
||||
count: _,
|
||||
code_position,
|
||||
|
||||
@@ -60,3 +60,14 @@ fn test_zerowidth() {
|
||||
state = state.search();
|
||||
assert!(state.string_position == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat_context_panic() {
|
||||
// pattern p = re.compile(r'(?:a*?(xx)??z)*')
|
||||
// START GENERATED by generate_tests.py
|
||||
#[rustfmt::skip] let p = Pattern { code: &[15, 4, 0, 0, 4294967295, 24, 25, 0, 4294967295, 27, 6, 0, 4294967295, 17, 97, 1, 24, 11, 0, 1, 18, 0, 17, 120, 17, 120, 18, 1, 20, 17, 122, 19, 1], flags: SreFlag::from_bits_truncate(32) };
|
||||
// END GENERATED
|
||||
let mut state = p.state("axxzaz", 0..usize::MAX);
|
||||
state = state.pymatch();
|
||||
assert!(state.marks == vec![Some(1), Some(3)]);
|
||||
}
|
||||
Reference in New Issue
Block a user