From 6ff6ccbdc9b2a029dfdfb4039a256a765b72242f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 4 May 2026 09:34:47 +0000 Subject: [PATCH 1/2] Initial plan From 87827eb0c379af0fa2ff01fd8043501c95fbb0af Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 4 May 2026 09:39:30 +0000 Subject: [PATCH 2/2] Fix off-by-one bug in modify() when removing last array element (issue #108) Agent-Logs-Url: https://github.com/microsoft/node-jsonc-parser/sessions/8c22962d-a4c5-4849-afa3-2eafdc3d47d0 Co-authored-by: aeschli <6461412+aeschli@users.noreply.github.com> --- src/impl/edit.ts | 2 +- src/test/edit.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/impl/edit.ts b/src/impl/edit.ts index 4ce554c..37d3301 100644 --- a/src/impl/edit.ts +++ b/src/impl/edit.ts @@ -109,7 +109,7 @@ export function setProperty(text: string, originalPath: JSONPath, value: any, op let previous = parent.children[removalIndex - 1]; let offset = previous.offset + previous.length; let parentEndOffset = parent.offset + parent.length; - edit = { offset, length: parentEndOffset - 2 - offset, content: '' }; + edit = { offset, length: parentEndOffset - 1 - offset, content: '' }; } else { edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' }; } diff --git a/src/test/edit.test.ts b/src/test/edit.test.ts index 5b57669..4e30f07 100644 --- a/src/test/edit.test.ts +++ b/src/test/edit.test.ts @@ -214,6 +214,18 @@ suite('JSON - edits', () => { assertEdit(content, edits, '// This is a comment\n[\n 1,\n "foo"\n]'); }); + test('remove last string item in array without formatting', () => { + let content = '{"items":["1","2"]}'; + let edits = modify(content, ['items', 1], void 0, {}); + assertEdit(content, edits, '{"items":["1"]}'); + }); + + test('remove last number item in array without formatting', () => { + let content = '{"items":[1,2]}'; + let edits = modify(content, ['items', 1], void 0, {}); + assertEdit(content, edits, '{"items":[1]}'); + }); + test('set property without formatting', () => { let content = '{\n "x": [1, 2, 3],\n "y": 0\n}';