Repository navigation
fix(connect): keep string contents when stripping trailing commas - #1768
Merged
Dumbris merged 1 commit intoOct 26, 2026
Conversation
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Dumbris
approved these changes
Oct 26, 2026
Dumbris
left a comment
Member
There was a problem hiding this comment.
Verified: the PR test fails on main for the reason described and passes on this branch merged with main; race tests for the touched packages and CI lint (bare and server tags) are clean. Also built and tested together with the rest of this batch, independently reviewed, and cross-reviewed with a second model.
Member
|
Merged. Thank you, @rudycelekli! |
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.
Bug
unmarshalLenientJSON(the JSONC fallback added for #922) removes trailing commas with the regex,\s*([}\]]). The regex has no notion of JSON strings, so it also rewrites, }and, ]inside string values. The fallback runs whenever strict parsing fails, for example on a hand-editedopencode.jsonwith one trailing comma. Connect, disconnect, undo and preview then work on the altered document, and connect writes it back to the client's config file. Another server's arguments are silently changed on disk.stripJSONComments, the other half of the same fallback, is already string-aware for exactly this reason.Trigger
~/.config/opencode/opencode.json:{ "mcp": { "other": {"type": "local", "command": ["sh", "-c", "echo {a, } [b, ]"]}, }, }After
mcpproxy connect opencode, the other server's command on disk is["sh", "-c", "echo {a} [b]"].Fix
Replace the regex with
stripTrailingCommas, a small scanner that tracks string and escape state the same waystripJSONCommentsdoes. It drops a,only when it is outside a string and the next non-whitespace byte is}or]. The now-unusedregexpimport is removed.Test
TestConnect_TrailingCommaCleanupPreservesStringContentsruns a realConnect("opencode", ...)on the file above and checks the other server's command is byte-for-byte unchanged after the write. The existing trailing-comma and JSONC tests still pass.Commands run
CGO_ENABLED=0 go vet ./internal/connect: cleanCGO_ENABLED=0 go test -count=1 ./internal/connect: okgit stashofconnect.go), the new test fails withother server's command rewritten: got ["sh" "-c" "echo {a} [b]"].gofmt -lon the edited files: no output