mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Match !important case-insensitively in SVG import CSS parser
Found while testing crates/svg/src/import/css.rs:25 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
d3a01307ea
commit
f8ad2edad8
@@ -22,7 +22,9 @@ pub(super) fn parse_decls(s: &str) -> Vec<(String, String, bool)> {
|
||||
.filter_map(|d| {
|
||||
let (k, v) = d.split_once(':')?;
|
||||
let v = v.trim();
|
||||
let (v, important) = match v.strip_suffix("important").map(str::trim_end).and_then(|v| v.strip_suffix('!')) {
|
||||
let stem = v.len().checked_sub("important".len()).and_then(|i| v.get(..i).zip(v.get(i..)));
|
||||
let flagged = stem.filter(|(_, kw)| kw.eq_ignore_ascii_case("important"));
|
||||
let (v, important) = match flagged.map(|(h, _)| h.trim_end()).and_then(|v| v.strip_suffix('!')) {
|
||||
Some(v) => (v.trim_end(), true),
|
||||
None => (v, false),
|
||||
};
|
||||
@@ -457,6 +459,14 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn important_flag_is_case_insensitive() {
|
||||
for s in ["fill: red !IMPORTANT", "fill: red !Important", "fill: red ! important"] {
|
||||
assert_eq!(parse_decls(s), [("fill".to_string(), "red".to_string(), true)], "{s}");
|
||||
}
|
||||
assert_eq!(parse_decls("fill: red !importantx"), [("fill".to_string(), "red !importantx".to_string(), false)]);
|
||||
}
|
||||
|
||||
fn with_doc(svg: &str, f: impl FnOnce(&roxmltree::Document, &Styles)) {
|
||||
let doc = roxmltree::Document::parse(svg).unwrap();
|
||||
let st = Styles::new(&doc);
|
||||
|
||||
Reference in New Issue
Block a user