mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-11 02:19:56 -06:00
Merge pull request #5473 from dotCooCoo/fix/ot-tag-double-sign
Reject doubly signed OpenType feature tags
This commit is contained in:
@@ -335,6 +335,21 @@ fn character_style_color_and_features_are_checked() {
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_style_rejects_doubly_signed_feature_tags() {
|
||||
let (mut s, id) = session_with_text("Text");
|
||||
let before = runs(&s, id);
|
||||
let undo = s.doc().unwrap().history.undo.len();
|
||||
for cmd in ["text.setStyle", "text.setRangeStyle"] {
|
||||
for tag in ["--liga", "+-dnom", "-+ss01", "++liga"] {
|
||||
let error = s.execute(cmd, &json!({"id": id, "start": 0, "end": 4, "features": [tag]})).unwrap_err().to_string();
|
||||
assert!(error.contains(&format!("`{tag}`")), "{cmd}: {error}");
|
||||
}
|
||||
}
|
||||
assert_eq!(runs(&s, id), before);
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn style_paints_count_as_swatch_uses_and_gradient_stops_are_checked() {
|
||||
let (mut s, _) = session_with_text("Text");
|
||||
|
||||
@@ -146,7 +146,7 @@ impl OtFeatures {
|
||||
|
||||
/// Is `tag` (optionally prefixed with `-` or `+`) one this set understands?
|
||||
pub fn known_tag(tag: &str) -> bool {
|
||||
let t = tag.trim_start_matches(['-', '+']);
|
||||
let t = tag.strip_prefix(['-', '+']).unwrap_or(tag);
|
||||
matches!(t, "liga" | "calt" | "dlig" | "smcp" | "frac" | "onum" | "tnum" | "ordn" | "swsh") || EXTRA_FEATURES.contains(&t)
|
||||
}
|
||||
|
||||
@@ -306,6 +306,9 @@ mod tests {
|
||||
assert!(OtFeatures::known_tag(t), "{t}");
|
||||
}
|
||||
assert!(!OtFeatures::known_tag("ss21"));
|
||||
for tag in ["--liga", "+-dnom", "-+ss01", "++liga"] {
|
||||
assert!(!OtFeatures::known_tag(tag), "{tag}");
|
||||
}
|
||||
let o = OtFeatures::from_tags(["ss03", "pnum", "sups", "-liga"]);
|
||||
assert_eq!(o.to_tags(), vec!["-liga", "ss03", "pnum", "sups"]);
|
||||
assert_eq!(OtFeatures::from_tags(["ss03", "-ss03"]).to_tags(), Vec::<String>::new(), "turned off again");
|
||||
|
||||
Reference in New Issue
Block a user