From 1331de2caa5f1255f42f7f1154b37bb09fdcd5cb Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Tue, 17 Nov 2026 13:36:47 -0700 Subject: [PATCH] fix(cli): derive subcommand help from the usage text; bounds-checked lexer slice; credits (M8) Fix-ups on the outside PRs merged in this batch: * #217: subcommand_usage reads the entries out of USAGE instead of keeping a second copy, so export, formats and guide search are covered and the two cannot drift apart. * #143: the surrogate-pair lookahead slices with get(), not an index. * #145 (declined, the reader is craft-xml now): pin that signed numeric character references stay text. * AUTHORS.md and CHANGELOG.md credit the contributors. --- AUTHORS.md | 5 ++++ CHANGELOG.md | 10 +++++++ crates/actions/src/as3/lex.rs | 2 +- crates/cli/src/lib.rs | 55 ++++++++++++++++++----------------- crates/xml/src/lib.rs | 7 +++++ 5 files changed, 51 insertions(+), 28 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index edbac412..b5f82c1f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -4,3 +4,8 @@ People who have contributed to AniCraft. The repository starts from one initial (`docs/release.md`), so the work before it is credited here. * Tanish Manku: project lead, product direction and design. +* Mex (MMexicann): SVG path data, `Math.round` and `Math.min`/`max` signed zeros, affine inverses, documentation. +* NetterSilver (Silvertree2010): shape tweens that morph a raw shape's line with its fill, dash patterns, colour, easing and script-string parsing. +* jayzed80: flipped scales in Properties, CLI subcommand help and frame numbering. +* Efe Şahinbaş (MacallanTheRoot): the MCP render caption. +* nocturney: localisation tests (Hebrew plurals, the product name). diff --git a/CHANGELOG.md b/CHANGELOG.md index c24cdf20..859e1755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ ## Unreleased +* **Fixes and polish from outside contributors.** Thank you all. + * **Shape tweens carry a raw shape's line with its fill** (#119, NetterSilver): when the two keyframes' lines have different numbers of pieces (a triangle into a hexagon), the pieces join into outlines that morph as the fill does, with no side left bare and no line left standing; a line on one keyframe only grows in or shrinks away, and shape hints steer the line too. + * **Flipping no longer squashes a shape to 1 %** (#116, jayzed80): the Scale fields in Properties show a mirrored scale as a negative percentage and never rewrite a value they only show. + * **SVG path data**: long runs of implicit line, curve and move commands keep every point (Mex). + * **Scripts**: `Math.round` keeps negative zero and `Math.min`/`Math.max` order signed zeros as ECMAScript does, in Test Movie and the HTML player alike (Mex); a surrogate pair written as two `\u` escapes in a string makes one character (NetterSilver). + * **Strokes**: an odd dash list of 9 to 15 lengths repeats whole instead of being cut mid-pattern, and a dotted line's spacing stays in range under overshooting eases (NetterSilver). + * **Geometry**: a rounded rectangle with a negative size is the same box as the plain one (NetterSilver), and a matrix whose inverse would overflow has none (Mex). + * **Commands**: a `bezier` ease with a malformed entry is refused rather than half-read, and a colour starting with `##` is not a colour (NetterSilver). + * **CLI and MCP**: `anicraft-cli --help` (and `help `) print that subcommand's usage (#153, jayzed80); the usage says which frame numbers are 1-based and which 0-based (#152, jayzed80); the MCP render caption reads `1280×720` (#311, Efe Şahinbaş); `--help` lists the light theme (Mex). + * **Docs**: plug-in element kinds and `null` bounds, opening Animate files directly from the CLI, and status notes that had gone out of date (Mex). Localisation tests for Hebrew dual plurals and the product name (nocturney). * **Security: safer reads and temp files.** Import to Library checks an image's size (256 MiB) before reading it, and saves, audio exports and the video soundtrack write their temporary files under unguessable names, created exclusively. * **Saved commands (command macros)** (ADR 0097, M6). * In the **History** panel, **Ctrl+click** steps (Shift+click a range) and choose **Save As diff --git a/crates/actions/src/as3/lex.rs b/crates/actions/src/as3/lex.rs index bc3bf0ba..ce96b1e5 100644 --- a/crates/actions/src/as3/lex.rs +++ b/crates/actions/src/as3/lex.rs @@ -206,7 +206,7 @@ impl Lexer<'_> { /// escape, and a lone surrogate becomes U+FFFD. fn utf16(&mut self, unit: u32) -> char { if (0xD800..0xDC00).contains(&unit) { - let rest = &self.src.as_bytes()[self.at..]; + let rest = self.src.as_bytes().get(self.at..).unwrap_or(&[]); let low = rest.strip_prefix(b"\\u").and_then(|r| r.get(..4)).and_then(|h| h.iter().try_fold(0u32, |v, &b| Some(v * 16 + char::from(b).to_digit(16)?))); if let Some(low) = low.filter(|l| (0xDC00..0xE000).contains(l)) { for _ in 0..6 { diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index bc9a2607..411dc2d8 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -131,34 +131,25 @@ fn one_based(a: &Args, k: &str) -> Result, String> { } } -/// Returns the usage line(s) for a given subcommand, formatted under `USAGE:`. +/// The usage of one subcommand, under `USAGE:`: its entries in [`USAGE`] with their +/// continuation lines, so the two never drift apart. `None` for a name [`USAGE`] doesn't list. pub fn subcommand_usage(cmd: &str) -> Option { - let body = match cmd { - "info" => " anicraft-cli info ", - "render" => " anicraft-cli render --out [--frame N] [--scale S]", - "render-seq" => " anicraft-cli render-seq --out-dir [--from A] [--to B] [--scale S]", - "gif" => " anicraft-cli gif --out [--from A] [--to B] [--scale S] [--overwrite yes]", - "apng" | "webp" => { - " anicraft-cli apng|webp --out [--from A] [--to B] [--scale S]\n [--loop forever|N] [--background yes] [--overwrite yes]\n full colour with real transparency (WebP: lossless)" + const ENTRY: &str = " anicraft-cli "; + let mut out = String::new(); + let mut taking = false; + // The entries are the block after `USAGE:`, up to the first blank line. + for line in USAGE.lines().skip_while(|l| *l != "USAGE:").skip(1).take_while(|l| !l.trim().is_empty()) { + if let Some(rest) = line.strip_prefix(ENTRY) { + // `apng|webp` names two subcommands; `--version` is also `version`. + let names = rest.split_whitespace().next().unwrap_or(""); + taking = names.split('|').any(|n| n == cmd || n.strip_prefix("--") == Some(cmd)); } - "commands" => " anicraft-cli commands", - "run" => " anicraft-cli run [--save ]", - "exec" => " anicraft-cli exec [] [--save ]", - "new" => " anicraft-cli new --out [--width W] [--height H] [--fps F]", - "guide" => " anicraft-cli guide --out writes the user guide as HTML pages (open index.html)", - "bench" => { - " anicraft-cli bench [--layers N] [--shapes N] [--frames N] performance probe (use --release)\n anicraft-cli bench --check yes the default scenario against the budgets in\n docs/performance.md; fails when one is missed" + if taking { + out.push('\n'); + out.push_str(line); } - "serve" => { - " anicraft-cli serve [file|--sample] JSON-lines on stdin/stdout:\n {\"id\":1,\"cmd\":\"draw.rect\",\"params\":{\"x\":10,\"y\":10,\"w\":50,\"h\":50}}" - } - "mcp" => { - " anicraft-cli mcp [file|--sample] Model Context Protocol server on stdin/stdout,\n for AI assistants (see docs/mcp.md)" - } - "version" => " anicraft-cli --version", - _ => return None, - }; - Some(format!("USAGE:\n{body}")) + } + (!out.is_empty()).then(|| format!("USAGE:{out}")) } /// Runs the CLI; returns the text to print on success. @@ -847,7 +838,7 @@ mod tests { #[test] fn subcommand_help_prints_usage() { - let subcommands = ["info", "render", "render-seq", "gif", "apng", "webp", "commands", "run", "exec", "new", "guide", "bench", "serve", "mcp"]; + let subcommands = ["info", "render", "render-seq", "gif", "apng", "webp", "export", "formats", "commands", "run", "exec", "new", "guide", "bench", "serve", "mcp"]; for sub in subcommands { let out_long = run(&[sub.to_string(), "--help".to_string()]).unwrap(); assert!(out_long.contains("USAGE:"), "help for {sub} should contain USAGE:"); @@ -874,12 +865,22 @@ mod tests { #[test] fn subcommand_usage_matches_usage_text() { let subcommands = - ["info", "render", "render-seq", "gif", "apng", "webp", "commands", "run", "exec", "new", "guide", "bench", "serve", "mcp", "version"]; + ["info", "render", "render-seq", "gif", "apng", "webp", "export", "formats", "commands", "run", "exec", "new", "guide", "bench", "serve", "mcp", "version"]; for sub in subcommands { let u = subcommand_usage(sub).expect("subcommand_usage should exist"); let body = u.strip_prefix("USAGE:\n").expect("should start with USAGE:\n"); assert!(USAGE.contains(body), "USAGE should contain body for {sub}"); } assert_eq!(subcommand_usage("bogus"), None); + // Every entry of a subcommand with several comes along, with its continuation lines. + let guide = subcommand_usage("guide").unwrap_or_default(); + assert!(guide.contains("guide --out") && guide.contains("guide search") && guide.contains("best first"), "{guide}"); + assert!(!guide.contains("bench"), "{guide}"); + let export = subcommand_usage("export").unwrap_or_default(); + assert!(export.contains("--options") && export.contains("exporter plug-ins"), "{export}"); + // Words inside an entry are not subcommands. + for word in ["anicraft-cli", "--sample", "file", "", "apng|webp", "--plugins"] { + assert_eq!(subcommand_usage(word), None, "{word:?}"); + } } } diff --git a/crates/xml/src/lib.rs b/crates/xml/src/lib.rs index ba5a69fc..a941d07c 100644 --- a/crates/xml/src/lib.rs +++ b/crates/xml/src/lib.rs @@ -244,6 +244,13 @@ mod tests { assert_eq!(root.text, "&bad;& c"); } + /// A numeric character reference is digits only (XML 1.0 §4.1): a sign makes it text. + #[test] + fn numeric_references_with_a_sign_stay_text() { + let root = parse(b"a&#+65;b&#x+41;c&#-65;dAAe").unwrap(); + assert_eq!(root.text, "a&#+65;b&#x+41;c&#-65;dAAe"); + } + #[test] fn mixed_text_stays_ordered_and_plain_indentation_stays_dropped() { let root = parse_mixed(b"Hello big world& more\n \n", &["text", "tspan"])