Skip to content

Preserve comments between patch value colon and value - #49

Open
Shubham-Padkonde wants to merge 1 commit into
tailscale:masterfrom
Shubham-Padkonde:fix/preserve-patch-value-comments
Open

Shubham-Padkonde wants to merge 1 commit into
tailscale:masterfrom
Shubham-Padkonde:fix/preserve-patch-value-comments

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Fixes #41.

Value.Patch drops comments between the "value": colon and the value. For example, "value": /* explanation */ 42 loses the explanation even though comments preceding the "value" member are retained.

Preserve those value-adjacent comments alongside the member's leading comments, retaining their order. Whitespace-only extras follow the existing behavior. This affects both add and replace operations without changing the patched JSON value.

Ten regression cases cover block and line comments when adding to arrays, objects and the document root, and replacing array/object entries. All ten fail before the fix; they verify both comments survive formatting and the resulting JSON is correct.

Validation:

  • Windows, Go 1.26.6 (CI version): go test ./... -count=1 and go vet ./... pass.
  • Linux, Go 1.27.1: go test -race ./... -count=1 passes.
  • gofmt and git diff --check pass.
  • macOS was not tested locally.

Prepared and tested with Codex assistance.

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.

Patching with comments

1 participant