Skip to content

Commit ebd1519

Browse files
committed
Fix resizing selector set
1 parent a42d1f3 commit ebd1519

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lol_html"
3-
version = "2.8.0"
3+
version = "2.8.1"
44
authors = ["Ivan Nikulin <inikulin@cloudflare.com, ifaaan@gmail.com>"]
55
license = "BSD-3-Clause"
66
description = "Streaming HTML rewriter/parser with CSS selector-based API"

src/selectors_vm/match_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl DenseHashSet {
7979
fn resize(&mut self, new_len: usize) -> &mut [u32] {
8080
let bits = self.slice_mut();
8181
let mut new = Vec::with_capacity(new_len);
82-
new.copy_from_slice(bits);
82+
new.extend_from_slice(bits);
8383
let cap = new.capacity();
8484
new.resize(cap, 0);
8585
*self = Self::Heap(new.into_boxed_slice());

src/selectors_vm/tests.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod vm_tests {
111111
($selectors:expr) => {{
112112
let mut ast = Ast::default();
113113

114-
for (selector, match_id) in $selectors.iter().zip(0..) {
114+
for (selector, match_id) in $selectors.into_iter().zip(0..) {
115115
ast.add_selector(&selector.parse().unwrap(), match_id);
116116
}
117117

@@ -133,7 +133,7 @@ mod vm_tests {
133133

134134
{
135135
let mut match_handler = |m: MatchInfo| {
136-
assert_eq!(m.with_content, $expectation.should_match_with_content);
136+
assert_eq!(m.with_content, $expectation.should_match_with_content, "with_content");
137137
matched_ids.insert(m.match_id);
138138
};
139139

@@ -168,7 +168,7 @@ mod vm_tests {
168168
}
169169
}
170170

171-
assert_eq!(matched_ids, $expectation.matched_ids);
171+
assert_eq!(matched_ids, $expectation.matched_ids, "{:?}", matched_ids.iter().collect::<Vec<_>>());
172172
}
173173
_ => panic!("Start tag expected"),
174174
}
@@ -1219,6 +1219,26 @@ mod vm_tests {
12191219
);
12201220
}
12211221

1222+
#[test]
1223+
fn lots_of_selectors() {
1224+
let mut vm = create_vm!(
1225+
('a'..='z').map(|c| c.to_string())
1226+
.chain(('A'..='Z').map(|c| format!("#{c}")))
1227+
.chain(('0'..='9').map(|c| format!("[data{c}]")))
1228+
);
1229+
1230+
exec_for_start_tag_and_assert!(
1231+
vm,
1232+
"<a id=Z>",
1233+
Namespace::Html,
1234+
Expectation {
1235+
should_bailout: true,
1236+
should_match_with_content: true,
1237+
matched_ids: DenseHashSet::from([0, 51]),
1238+
}
1239+
);
1240+
}
1241+
12221242
/// Test that match_handler is called exactly once per matched id,
12231243
/// even when the same match_ids can be reached through multiple instruction paths.
12241244
/// For example, `"span, [foo$=bar]"` is one selector (match_id 0) with two

0 commit comments

Comments
 (0)