mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-19 00:17:32 +00:00
Lasso: refuse a history name that shows nothing or hides formatting
A historyName of zero-width, filler or BOM characters showed an empty History row, and a bidi control or line separator could make a row read differently from its name. A history name now has no control or line-break character anywhere, loses white space and ZWNJ/ZWJ at its ends, and is then held to the plug-in menu-label rule, now shared as photocraft_plugins::manifest::printable_name (1-64 characters with a visible one, no hidden format characters; plug-in names also refuse U+2028/U+2029).
This commit is contained in:
1 parent
60d0895c27
commit
be7ebc078a
3 files changed
+58
-7
No files matched your search
@@ -143,9 +143,7 @@ impl Manifest {
|
||||
if !valid_id(&self.id) {
|
||||
return Err(Error::Manifest(format!("invalid id {:?}: use 1-64 characters from A-Z a-z 0-9 . _ -", self.id)));
|
||||
}
|
||||
let name = self.name.trim();
|
||||
let printable = name.chars().all(|c| !c.is_control() && !hidden_format(c)) && name.chars().any(visible);
|
||||
if !printable || name.chars().count() > 64 {
|
||||
if !printable_name(self.name.trim()) {
|
||||
return Err(Error::Manifest("`name` must be 1-64 printable characters".into()));
|
||||
}
|
||||
if self.version.len() > 32 || self.description.len() > 1024 || self.author.len() > 128 {
|
||||
@@ -399,6 +397,12 @@ fn hidden_format(c: char) -> bool {
|
||||
!matches!(c, '\u{200C}' | '\u{200D}') && in_ranges(c, FORMAT)
|
||||
}
|
||||
|
||||
/// Whether `name` (already trimmed) can be shown as a label: 1-64 characters, at least one of them
|
||||
/// visible, and no control characters, line or paragraph separators, or hidden format characters.
|
||||
pub fn printable_name(name: &str) -> bool {
|
||||
name.chars().count() <= 64 && name.chars().any(visible) && !name.chars().any(|c| c.is_control() || matches!(c, '\u{2028}' | '\u{2029}') || hidden_format(c))
|
||||
}
|
||||
|
||||
/// A character that draws something on its own.
|
||||
fn visible(c: char) -> bool {
|
||||
!c.is_whitespace() && !c.is_control() && !in_ranges(c, FORMAT) && !in_ranges(c, BLANK)
|
||||
@@ -631,6 +635,8 @@ mod tests {
|
||||
"\u{3164}\u{FE0F}",
|
||||
" \u{3000} ",
|
||||
"Tone\u{7}",
|
||||
"Tone\u{2028}Pro",
|
||||
"Tone\u{2029}Pro",
|
||||
] {
|
||||
assert!(with_name(bad).is_err(), "{bad:?}");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user