fix crash associated with trailing/repeating commas within srcset
This commit is contained in:
parent
8ad252868e
commit
8adf059980
2 changed files with 38 additions and 4 deletions
10
src/html.rs
10
src/html.rs
|
@ -159,10 +159,12 @@ pub fn embed_srcset(
|
|||
let srcset_items: Vec<&str> = srcset.split(',').collect();
|
||||
for srcset_item in srcset_items {
|
||||
let parts: Vec<&str> = srcset_item.trim().split_whitespace().collect();
|
||||
let path = parts[0].trim();
|
||||
let descriptor = if parts.len() > 1 { parts[1].trim() } else { "" };
|
||||
let srcset_real_item = SrcSetItem { path, descriptor };
|
||||
array.push(srcset_real_item);
|
||||
if parts.len() > 0 {
|
||||
let path = parts[0].trim();
|
||||
let descriptor = if parts.len() > 1 { parts[1].trim() } else { "" };
|
||||
let srcset_real_item = SrcSetItem { path, descriptor };
|
||||
array.push(srcset_real_item);
|
||||
}
|
||||
}
|
||||
|
||||
let mut result: String = str!();
|
||||
|
|
|
@ -29,3 +29,35 @@ mod passing {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗
|
||||
// ██╔════╝██╔══██╗██║██║ ██║████╗ ██║██╔════╝
|
||||
// █████╗ ███████║██║██║ ██║██╔██╗ ██║██║ ███╗
|
||||
// ██╔══╝ ██╔══██║██║██║ ██║██║╚██╗██║██║ ██║
|
||||
// ██║ ██║ ██║██║███████╗██║██║ ╚████║╚██████╔╝
|
||||
// ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
||||
|
||||
#[cfg(test)]
|
||||
mod failing {
|
||||
use reqwest::blocking::Client;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::html;
|
||||
use crate::opts::Options;
|
||||
|
||||
#[test]
|
||||
fn trailing_comma() {
|
||||
let cache = &mut HashMap::new();
|
||||
let client = Client::new();
|
||||
let srcset_value = "small.png 1x, large.png 2x,";
|
||||
let mut options = Options::default();
|
||||
options.no_images = true;
|
||||
options.silent = true;
|
||||
let embedded_css = html::embed_srcset(cache, &client, "", &srcset_value, &options, 0);
|
||||
|
||||
assert_eq!(
|
||||
format!("{} 1x, {} 2x", empty_image!(), empty_image!()),
|
||||
embedded_css
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue