Skip to content

Commit 4d8f410

Browse files
committed
fix(rust): further select fixes
1 parent 02caa72 commit 4d8f410

File tree

1 file changed

+6
-3
lines changed
  • apps/api/sharedLibs/html-transformer/src

1 file changed

+6
-3
lines changed

apps/api/sharedLibs/html-transformer/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ fn _transform_html_inner(opts: TranformHTMLOptions) -> Result<String, ()> {
268268
}
269269
}
270270

271-
for img in document.select("img[srcset]")? {
271+
let srcset_images: Vec<_> = document.select("img[srcset]")?.collect();
272+
for img in srcset_images {
272273
let mut sizes: Vec<ImageSource> = img.attributes.borrow().get("srcset").ok_or(())?.split(",").filter_map(|x| {
273274
let tok: Vec<&str> = x.trim().split(" ").collect();
274275
let tok_1 = if tok.len() > 1 && !tok[1].is_empty() {
@@ -306,14 +307,16 @@ fn _transform_html_inner(opts: TranformHTMLOptions) -> Result<String, ()> {
306307

307308
let url = Url::parse(&opts.url).map_err(|_| ())?;
308309

309-
for img in document.select("img[src]")? {
310+
let src_images: Vec<_> = document.select("img[src]")?.collect();
311+
for img in src_images {
310312
let old = img.attributes.borrow().get("src").map(|x| x.to_string()).ok_or(())?;
311313
if let Ok(new) = url.join(&old) {
312314
img.attributes.borrow_mut().insert("src", new.to_string());
313315
}
314316
}
315317

316-
for anchor in document.select("a[href]")? {
318+
let href_anchors: Vec<_> = document.select("a[href]")?.collect();
319+
for anchor in href_anchors {
317320
let old = anchor.attributes.borrow().get("href").map(|x| x.to_string()).ok_or(())?;
318321
if let Ok(new) = url.join(&old) {
319322
anchor.attributes.borrow_mut().insert("href", new.to_string());

0 commit comments

Comments
 (0)