[Routine - QP] fix: guard against non-array JSON in MCP clipboard history load#47
Draft
winterdrive wants to merge 1 commit into
Draft
[Routine - QP] fix: guard against non-array JSON in MCP clipboard history load#47winterdrive wants to merge 1 commit into
winterdrive wants to merge 1 commit into
Conversation
ClipboardTools.loadHistory() cast parsed JSON directly to
ClipboardHistoryItem[] without checking it was actually an array,
so a corrupted or unexpectedly-shaped clipboard-history.json (e.g.
`{}` or `null`) would silently produce an object masquerading as
an array, leading to NaN bounds checks and a leaked internal error
message in getClipboardItem. Mirrors the existing array guard
already used in src/ClipboardManager.ts.
This was referenced Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Pre-flight Check
Open PRs / active routine branches checked before starting:
routine/qp-fix-versionhistory-substr-260703— touchessrc/services/VersionHistoryService.tschore/ignore-claude-worktrees-jest— touchesjest.config.jsroutine/qp-fix-path-traversal-prefix-260702— touchessrc/core/PathUtils.ts,src/test/unit/pathUtils.test.tsfix/quick-create-workspace-ux— touchessrc/commands.ts,src/promptProvider.ts,src/test/unit/promptProviderMultiroot.test.tsAlso reviewed several closed-but-not-merged
routine/qp-fix-*branches (e.g.qp-fix-corrupted-clipboard-json-260626/ PR #34) to understand prior work in this area — that one guardedsrc/ClipboardManager.tsagainst non-array JSON, but the equivalent gap in the MCP server's clipboard tool (mcp-server/src/tools/clipboardTools.ts) was never fixed and that PR is closed.This PR only touches
mcp-server/src/tools/clipboardTools.ts, which is not modified by any of the above — no overlap.2. Changes
ClipboardTools.loadHistory()castJSON.parse(data)straight toClipboardHistoryItem[]with no shape check. If~/.quickprompt/clipboard-history.jsonis valid JSON but not an array (e.g. corrupted to{}ornull), the object masquerades as an array downstream ingetClipboardItem():history.lengthbecomesundefined, bounds checks againstNaNalways pass, and the code falls through tohistory[targetIndex].content, throwing an unhandled-shapeTypeErrorthat surfaces as a raw internal error message to the MCP client.Fix: parse into
unknownfirst and fall back to[]when the result isn't an array, matching the existing guard already used insrc/ClipboardManager.ts.mcp-server/src/tools/.package.json,package-lock.json, orCHANGELOG.md.3. Safety Verification
Commands run locally, all passed:
npx tsc -p ./— no errorsnpm run test(jest --runInBand) — 7 suites / 107 tests passed4. CI / Release Gate Note
This is a daily routine Draft PR. Package version bump and CHANGELOG consolidation are intentionally deferred to the weekend release/integration PR. If CI fails only due to the repo's version-bump release gate, that is expected release-readiness behavior for a routine PR, not a code validation failure.
🤖 Generated with Claude Code