fix(rust): EqCapture accepted cases where number of captured nodes differed by one

Problem: When using alternations, the `#eq?` predicate does not always use the same capture name.

Solution: Iterate the left and right captured nodes more independently.
This commit is contained in:
Quentin LE DILAVREC 2025-08-27 10:25:29 +02:00 committed by GitHub
parent 0a7274678a
commit 79177a1cd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 3 deletions

View file

@ -3355,9 +3355,11 @@ impl<'tree> QueryMatch<'_, 'tree> {
.iter()
.all(|predicate| match predicate {
TextPredicateCapture::EqCapture(i, j, is_positive, match_all_nodes) => {
let mut nodes_1 = self.nodes_for_capture_index(*i);
let mut nodes_2 = self.nodes_for_capture_index(*j);
while let (Some(node1), Some(node2)) = (nodes_1.next(), nodes_2.next()) {
let mut nodes_1 = self.nodes_for_capture_index(*i).peekable();
let mut nodes_2 = self.nodes_for_capture_index(*j).peekable();
while nodes_1.peek().is_some() && nodes_2.peek().is_some() {
let node1 = nodes_1.next().unwrap();
let node2 = nodes_2.next().unwrap();
let mut text1 = text_provider.text(node1);
let mut text2 = text_provider.text(node2);
let text1 = node_text1.get_text(&mut text1);