mirror of
https://github.com/Y2Z/monolith
synced 2024-11-10 19:10:29 +00:00
Merge pull request #227 from snshn/fix-trailing-comma-for-srcset-parsing
Fix crash associated with trailing/repeating commas within srcset
This commit is contained in:
commit
2b9caf9840
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 New Issue
Block a user