Skip to content

fix: reject negative --index in ExcelHandler.Add and PowerPointHandler.Add - #225

Open
Marnie0415 wants to merge 1 commit into
iOfficeAI:mainfrom
Marnie0415:fix/reject-negative-index-excel-ppt
Open

fix: reject negative --index in ExcelHandler.Add and PowerPointHandler.Add#225
Marnie0415 wants to merge 1 commit into
iOfficeAI:mainfrom
Marnie0415:fix/reject-negative-index-excel-ppt

Conversation

@Marnie0415

@Marnie0415 Marnie0415 commented Jul 14, 2026

Copy link
Copy Markdown

Summary

Add negative --index validation to ExcelHandler.Add and PowerPointHandler.Add, matching the existing guard in WordHandler.Add (line 49-54).

Problem

WordHandler.Add rejects negative --index values with a clean "--index must be non-negative." error. ExcelHandler.Add and PowerPointHandler.Add lack this guard — a negative index propagates into collection indexing and surfaces as a raw .NET ArgumentOutOfRangeException.

Fix

Add the same early validation check at the top of each handler's Add method, before the index is used for any collection operation.

Affected paths

This guard covers all three entry points that call handler.Add:

  • CLI non-resident: CommandBuilder.Add.cs
  • Resident/MCP: ResidentServer.ExecuteAdd
  • Batch: CommandBuilder.ExecuteBatchItem

Verification

# 1. Excel — should get clean error
officecli create test.xlsx
officecli add test.xlsx /Sheet1 row --index -1
# Before: raw ArgumentOutOfRangeException
# After: "--index must be non-negative." error, exit 1

# 2. PowerPoint — same behavior
officecli create test.pptx
officecli add test.pptx / slide --index -1

# 3. Verify normal (non-negative) index still works
officecli add test.xlsx /Sheet1 row --index 0
# Should succeed

Testing

  • Verified negative index rejected for xlsx
  • Verified negative index rejected for pptx
  • Verified non-negative index works normally
  • Verified batch path also enforces the guard (via ExecuteBatchItemhandler.Add)

Breaking Changes

None. Only invalid inputs (negative --index) now get a clean error instead of undefined behavior. Valid inputs are unaffected.

Notes

  • Minimal change: +15 lines across 2 files
  • Pattern copied verbatim from WordHandler.Add.cs line 49-54

…r.Add

WordHandler.Add already rejects negative --index values (line 49-54)
with a clean error message. ExcelHandler.Add and PowerPointHandler.Add
lack this guard — a negative index propagates to collection indexing
and surfaces as a raw ArgumentOutOfRangeException.

Add the same early validation so all three handlers behave consistently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant