Skip to content

Commit a9ed2b9

Browse files
authored
Merge pull request #1896 from Mark-Simulacrum/fix-ignore-adjacency
Fix adjacent ignore block handling
2 parents fedb383 + 08262ea commit a9ed2b9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

parser/src/ignore_block.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl IgnoreBlocks {
5454
pub fn overlaps_ignore(&self, region: Range<usize>) -> Option<Range<usize>> {
5555
for ignore in &self.ignore {
5656
// See https://stackoverflow.com/questions/3269434.
57-
if ignore.start <= region.end && region.start <= ignore.end {
57+
// We have strictly < because `end` is not included in our ranges.
58+
if ignore.start < region.end && region.start < ignore.end {
5859
return Some(ignore.clone());
5960
}
6061
}
@@ -77,13 +78,16 @@ fn bodies(s: &str) -> Vec<Ignore<'_>> {
7778
for range in &cbs.ignore {
7879
let range = range.clone();
7980
if previous.end != range.start {
81+
assert!(cbs.overlaps_ignore(previous.end..range.start).is_none());
8082
bodies.push(Ignore::No(&s[previous.end..range.start]));
8183
}
84+
assert!(cbs.overlaps_ignore(range.clone()).is_some());
8285
bodies.push(Ignore::Yes(&s[range.clone()]));
8386
previous = range.clone();
8487
}
8588
if let Some(range) = cbs.ignore.last() {
8689
if range.end != s.len() {
90+
assert!(cbs.overlaps_ignore(range.end..s.len()).is_none());
8791
bodies.push(Ignore::No(&s[range.end..]));
8892
}
8993
}
@@ -282,3 +286,14 @@ This is an HTML comment.
282286
],
283287
);
284288
}
289+
290+
#[test]
291+
fn cbs_13() {
292+
assert_eq!(
293+
bodies("<!-- q -->\n@rustbot label +F-trait_upcasting"),
294+
[
295+
Ignore::Yes("<!-- q -->\n"),
296+
Ignore::No("@rustbot label +F-trait_upcasting")
297+
],
298+
);
299+
}

0 commit comments

Comments
 (0)