Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/officecli/Handlers/Excel/ExcelHandler.Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public string Add(string parentPath, string type, InsertPosition? position, Dict
{
Modified = true;
var index = position?.Index;

// Reject negative --index up front with a clean message instead of
// letting it fall through and surface as a raw .NET
// ArgumentOutOfRangeException from collection indexing. Matches
// the guard in WordHandler.Add.
if (index.HasValue && index.Value < 0)
throw new ArgumentException("--index must be non-negative.");

// Normalize to case-insensitive lookup so camelCase keys (e.g. minColor) match lowercase lookups.
// Preserve TrackingPropertyDictionary so handler-as-truth read
// tracking survives — its comparer wraps OrdinalIgnoreCase already.
Expand Down
7 changes: 7 additions & 0 deletions src/officecli/Handlers/Pptx/PowerPointHandler.Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public string Add(string parentPath, string type, InsertPosition? position, Dict
parentPath = ResolveIdPath(parentPath);
parentPath = ResolveLastPredicates(parentPath);

// Reject negative --index up front with a clean message instead of
// letting it fall through and surface as a raw .NET
// ArgumentOutOfRangeException from collection indexing. Matches
// the guard in WordHandler.Add.
if (position?.Index.HasValue == true && position.Index.Value < 0)
throw new ArgumentException("--index must be non-negative.");

// Resolve --after/--before to index (handles find: prefix)
var index = ResolveAnchorPosition(parentPath, position);

Expand Down