#414·OfficeCLI

set/add: an unknown option placed after `--prop` is swallowed into the property values — so the guard written to catch it (which names `--at A2`) never fires, and the same token is refused one position earlier

Author: argszeroCreated Sep 20, 2026Updated Sep 21, 2026

Summary

set and add declare --prop as a multi-value option (Option<string[]> with AllowMultipleArgumentsPerToken = true), which makes it a greedy token sink: every following token that is not a recognized option is consumed as a property value.

Two consequences fall out of that one declaration:

  1. An unknown option placed after --prop never reaches the guard written to catch it. RejectUnknownOptionTokens (CommandBuilder.cs:1611) exists precisely for this, and its own doc-comment names the motivating case:

    "Commands parsed with TreatUnmatchedTokensAsErrors=false otherwise swallow unknown flags (e.g. add ... --at A2) silently with exit 0 — the element lands somewhere the caller did not intend and nothing surfaces the typo."

    But because the sink has already eaten the token, it never appears in UnmatchedTokens, so the guard cannot see it. The same token is refused or silently swallowed depending only on its position relative to --prop:

    command line rc result
    add f.xlsx /Sheet1 --type sheet --zzz A2 --prop name=S9 1 Unrecognized option '--zzz'.
    add f.xlsx /Sheet1 --type sheet --prop name=S9 --zzz A2 0 Added sheet at /S9 — nothing reported
  2. A --prop value without = is dropped with no branch to report it. ParsePropsArray (CommandBuilder.cs:1285) treats eqIdx == 0 as a hard error — added deliberately by a6ed9fe5 ("fix(cli): reject --prop with empty key instead of silent drop"), whose comment gives the reason as "So AI callers don't waste a turn wondering why their property had no effect." The other malformed form, eqIdx == -1, has no branch at all — the value is simply never stored:

    command line rc warnings
    set f.xlsx /Sheet1/A1 --prop value=NEW BARE 0 none
    set f.xlsx /Sheet1/A1 --prop value=NEW bogusprop=1 2 unsupported_property (the positive control — see below)
  3. set calls the guard nowhere. The only call site of RejectUnknownOptionTokens is Add.cs:123; Set.cs does not reference it. So even when a token does land in UnmatchedTokens (--prop not yet seen), set does not name it: set f.xlsx /Sheet1/A1 --zzz A2 --prop value=NEW → rc 0, where the identical shape on add → rc 1.

Environment

  • OfficeCLI 1.0.151 (released binary), macOS 26.6.2 arm64
  • Source read at both revisions: the working tree (local HEAD 1f0fd193) and origin/main (dced0d74). git diff HEAD origin/main over the three files involved (CommandBuilder.cs, CommandBuilder.Set.cs, CommandBuilder.Add.cs) contains only an unrelated move --index help-text change, so every anchor below also holds in the revision the released binary was built from.
  • No .NET SDK on this machine: every behavioural row is measured on the released binary; every source claim is read-from-source and labelled as such.

The position experiment (measured)

Method: each shape on a freshly created file seeded with sentinels (A1=BASE, B1=BEEE), so a swallowed argument shows up as "the sentinel still stands". Outcomes are read from the JSON envelope and from the sheet XML bytes, not from the prose.

shape rc observed
add … --zzz A2 (no --prop anywhere) 1 Unrecognized option '--zzz'. — guard fires
add … --zzz A2 --prop name=S9 (junk before --prop) 1 Unrecognized option '--zzz'. — guard fires
add … --prop name=S9 --zzz A2 (junk after --prop) 0 Added sheet at /S9 — guard blind, token became a property value
add … --prop name=S9 JUNK 0 Added sheet at /S9 — same
set … --prop value=NEW --zzz A2 0 Updated /Sheet1/A1: value=NEW
set … --zzz A2 --prop value=NEW (junk before --prop) 0 Updated /Sheet1/A1 — set never calls the guard (contrast row 2)
set … --prop value=NEW BARE 0 no warnings key at all
set … --prop value=NEW bogusprop=1 2 warnings: [{code: unsupported_property, …bogusprop…}] — positive control
get … /Sheet1/A1 /Sheet1/B1 1 Unrecognized command or argument '/Sheet1/B1'. — control
remove … /Sheet1/B1 /Sheet1/A1 1 Unrecognized command or argument '/Sheet1/A1'. — control

The bogusprop=1 row is the load-bearing control: it proves the token really is being read as a property value (the sink exists), and it is the only one of these shapes that the existing warning machinery covers.

The strict verbs are otherwise strict — get, remove, validate, query, dump, raw, view all refuse a stray positional with Unrecognized command or argument '<tok>'. (rc 1). The tolerance introduced by TreatUnmatchedTokensAsErrors = false is confined to set and add, which is exactly why two checkers were written for it — but neither covers the shapes above.

Where it comes from (read from source)

The sink — src/officecli/CommandBuilder.Set.cs:17 and src/officecli/CommandBuilder.Add.cs:42:

csharp
var propsOpt = new Option<string[]>("--prop") { Description = "Property to set (key=value)", AllowMultipleArgumentsPerToken = true };

The tolerance the guards exist for — Set.cs:23, Add.cs:45:

csharp
var setCommand = new Command("set", "Modify a document node's properties") { TreatUnmatchedTokensAsErrors = false };

The guard, its blind spot, and its call sites — src/officecli/CommandBuilder.cs:1611-1637:

csharp
for (int i = 0; i < tokens.Count; i++)
{
    var token = tokens[i];
    if (!token.StartsWith("--") || token.Length <= 2) continue;   // line 1622: only ever inspects --tokens
    …
    throw new OfficeCli.Core.CliException($"Unrecognized option '{token}'.") { Code = "invalid_argument", … };
}

It iterates parseResult.UnmatchedTokens — a collection the sink has already removed the token from. Note also line 1622: a bare stray token (a second path, a stray word) is skipped by design, so this guard could not have caught the dropped-target case either. The only call site is Add.cs:123.

The drop — src/officecli/CommandBuilder.cs:1290-1321:

csharp
var eqIdx = prop.IndexOf('=');
// BUG-R40-B12: previously `eqIdx > 0` silently dropped both …
if (eqIdx == 0) throw new ArgumentException(…);   // line 1296 — hardened
if (eqIdx > 0) { … dict[key] = value; }           // line 1299 — the only storing branch
// eqIdx == -1: no branch — the value is never stored and nothing reports it

The commit that added line 1296 is a6ed9fe5, and the reasoning in its comment applies verbatim to the case it left unhandled.

Why this is more than an ugly error message

  • The realistic harm is a dropped target, not a noisy typo. set f.xlsx /Sheet1/A1 /Sheet1/B1 --prop value=NEW returns rc 0, writes A1, and leaves B1 untouched (measured). get and remove refuse a second path with the generic message; set accepts and discards it. Same for a range followed by a cell, or a second sheet.
  • The outcome is position-dependent, which no design would state. The guard fires for --zzz A2 one token earlier and is blind one token later. That is an artifact of the sink, not a rule.
  • set is the most-used mutation verb and has no guard call at all — on set, a stray option is only ever masked, never named. (When there are no props, an unrelated check happens to fire: set … --nope value=CH6 → rc 2 missing_prop_flag; set … --definitely-not-an-option → rc 1 missing_property. Neither names the offending option, and neither fires when a valid --prop is also present.)
  • This project has already ruled that this class is a defect. 3a5e4772 added the guard specifically to stop unknown options being swallowed with exit 0, and a6ed9fe5 hardened the empty-key form of exactly this parse loop for exactly this reason.

What I am not disputing: the caller wrote a malformed command line. The ask is that malformed input be refused — as it already is one position earlier, and as it already is in the eight strict verbs — rather than converted into a property value that is then dropped.

Suggested fix shape

  1. Call RejectUnknownOptionTokens from set too — it already has result in hand at Set.cs:139, right next to the DetectUnmatchedKeyValues call.
  2. Defeat the sink: after parsing, any element of the props array that starts with -- is a stray option, not a property value, and can be refused with the existing Unrecognized option message. (Measured: that is exactly where --zzz currently lands.)
  3. Give eqIdx == -1 in ParsePropsArray the same treatment BUG-R40-B12 gave eqIdx == 0 — the author's own stated reason applies unchanged.
  4. Optional, same family: a bare non-key=value token in set/add (e.g. a second path) refused the way get/remove already refuse it.

Constraints to preserve (all measured as currently correct):

  • --prop a=1 --prop b=2 and --prop a=1 b=2 — the multi-argument form is deliberate and used throughout the docs
  • the missing_prop_flag warning for a bare k=v (rc 2)
  • the missing_property error for a set with no props at all (rc 1)
  • the --props/-props/--prop= typo hint (Pattern 3 in DetectUnmatchedKeyValues)
  • the strict verbs' generic refusal

I have not prepared a patch — no .NET SDK on this machine, so the fix is text-verified only, not compiled or test-run.

Reproduction

bash
officecli create a.xlsx

# the guard fires when the junk precedes --prop
officecli add a.xlsx /Sheet1 --type sheet --zzz A2 --prop name=S9 --json ; echo "rc=$?"
#   rc=1  "Unrecognized option '--zzz'."

# the same token one position later is swallowed
officecli add a.xlsx /Sheet1 --type sheet --prop name=S9 --zzz A2 --json ; echo "rc=$?"
#   rc=0  "Added sheet at /S9"

# set does not call the guard at all
officecli set a.xlsx /Sheet1/A1 --zzz A2 --prop value=NEW --json ; echo "rc=$?"
#   rc=0  "Updated /Sheet1/A1"

# a --prop value without '=' vanishes silently
officecli set a.xlsx /Sheet1/A1 --prop value=NEW BARE --json        # rc=0, no "warnings"

# positive control: a swallowed value WITH '=' really is read as a property
officecli set a.xlsx /Sheet1/A1 --prop value=NEW bogusprop=1 --json ; echo "rc=$?"
#   rc=2  warnings: [{code: "unsupported_property", … bogusprop …}]

# the realistic harm: a second target is accepted and dropped
officecli set a.xlsx /Sheet1/A1 --prop value=BASE
officecli set a.xlsx /Sheet1/B1 --prop value=BEEE
officecli set a.xlsx /Sheet1/A1 /Sheet1/B1 --prop value=NEW --json   # rc=0, A1=NEW, B1 still BEEE

Not the same as other open reports

  • #405 (closed) — unknown property keys silently discarded on add / generic error on set. Here the token is a stray option, and the second half is a property value with no =. Different code path (UnmatchedTokens plumbing and ParsePropsArray), though the same family.
  • #399 §5 (ours, open) — the unknown-prop-key behaviour, inside a docs/consistency umbrella. This report is the neighbouring mechanism; I have not duplicated it there.
  • #413 (ours) — import truncating its <parent-path> to the first segment. A different argument, a different verb, a different mechanism. (Relatedly: get/set do run the cell validator on A1/B2 — which is what makes #413's import an outlier.)
  • query selectors that match nothing (matches: 0) and import refusing extra positionals are both correct behaviour — recorded so they are not mistaken for this.

Scope / honesty

  • Behaviour measured on macOS arm64, OfficeCLI 1.0.151 only — Windows and Linux not measured.
  • Source claims are read from origin/main @ dced0d74 and the working tree @ 1f0fd193 (the two differ only by an unrelated help string in Add.cs); nothing here is compiled, and the fix shape is a proposal, not a verified patch.
  • move and swap also carry a --prop option (Add.cs:425) and were not swept for the same sink — flagged as unmeasured rather than claimed.
  • The MCP and batch surfaces pass props as JSON objects, where this sink cannot exist by construction; no claim is made about them.
  • Each shape above ran on a freshly created file, so no resident warm state carried between them.