Type: Kinsoku Shori sets refuse a null field

type.kinsokuSets.set read a null value as a key left out, so
`cannotStart: null` cleared that category and `from: null` made a
renamed set look new to the paragraphs using it. A null value now
fails the call and changes nothing.
This commit is contained in:
dotCooCoo
2026-11-14 14:57:35 -08:00
parent dc89f8d953
commit c534b8ea83
3 changed files with 11 additions and 3 deletions
+4
View File
@@ -174,6 +174,10 @@ fn parse_set(v: &Value, c: &str) -> Result<(KinsokuSet, Option<String>)> {
if let Some(k) = o.keys().find(|k| !SET_KEYS.contains(&k.as_str())) {
return Err(bad(c, format!("unknown key `{k}`; a set takes {}", SET_KEYS.join(", "))));
}
// A null value is refused rather than read as a key left out.
if let Some(k) = o.iter().find_map(|(k, v)| v.is_null().then_some(k)) {
return Err(bad(c, format!("`{k}` can't be null; leave it out instead")));
}
let raw = o.get("name").and_then(Value::as_str).ok_or_else(|| bad(c, "each set needs a name"))?;
let name = KinsokuSet::clean_name(raw).ok_or_else(|| {
bad(c, format!("`{raw}` can't name a Kinsoku set (1 to {KINSOKU_NAME_MAX} characters, no control characters, not None, Hard or Soft)"))
+5 -1
View File
@@ -62,7 +62,8 @@ fn kinsoku_sets_are_set_as_one_undo_step_and_saved() {
/// The sets are checked before anything changes: a built-in name, a blank or too-long name, two
/// sets of one name in any case, an unknown key, a sequence of one character or with a space, a
/// control character, a `from` the document has no set of, and more than 256 sets all fail.
/// control character, a `from` the document has no set of, a null value, and more than 256 sets
/// all fail.
#[test]
fn kinsoku_sets_refuse_what_a_set_cannot_hold() {
let mut s = session();
@@ -83,6 +84,9 @@ fn kinsoku_sets_refuse_what_a_set_cannot_hold() {
json!([{"name": "A", "cannotStart": ["あ"]}]),
json!([{"name": "A", "from": "Missing"}]),
json!([{"name": "A", "from": "Tight"}, {"name": "B", "from": "tight"}]),
json!([{"name": "Tight", "from": "Tight", "cannotStart": null}]),
json!([{"name": "Tight", "from": null}]),
json!([{"name": "A", "inseparable": null}]),
json!((0..257).map(|i| json!({"name": format!("S{i}")})).collect::<Vec<_>>()),
] {
assert!(s.execute("type.kinsokuSets.set", &json!({"sets": bad})).is_err(), "{bad}");
+2 -2
View File
@@ -8705,8 +8705,8 @@ sequence counts each of its characters); a control or space character in a categ
case and never None, Hard or Soft; a document holds at most 256 sets. These limits are VectorCraft's own. A set with
the name of a set the document has (any case) and no `from` edits that set; `from` names the set it renames. Every
paragraph and paragraph style using an edited set takes its new characters and name, and those using a set left out
take Hard. An unknown key, a name used twice, a `from` the document has no set of and a sequence of one character fail
the call and change nothing. The built-in None, Hard and Soft are not stored and can't be changed. → `{sets}`.
take Hard. An unknown key, a null value, a name used twice, a `from` the document has no set of and a sequence of one
character fail the call and change nothing. The built-in None, Hard and Soft are not stored and can't be changed. → `{sets}`.
`type.kinsokuSets.list` returns the sets with how many paragraphs (`paragraphs`), paragraph styles (`styles`) and graphs
(`graphs`, in the paragraph attributes a graph keeps for its labels) use each. `type.kinsokuSets.base {base: "hard"|"soft"|"none"|name, name?}` returns the categories a new set based on a