diff --git a/src/html.rs b/src/html.rs
index bfe19e6..6c6db2d 100644
--- a/src/html.rs
+++ b/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!();
diff --git a/src/tests/html/embed_srcset.rs b/src/tests/html/embed_srcset.rs
index 5489c86..0fa2b2b 100644
--- a/src/tests/html/embed_srcset.rs
+++ b/src/tests/html/embed_srcset.rs
@@ -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
+ );
+ }
+}