fix(publisher): validate JSON encoding before publishing to catch Windows codepage corruption#1439
Closed
hiro-nikaitou wants to merge 1 commit into
Closed
Conversation
…dows codepage corruption On Windows systems running under Git Bash/MSYS with a non-UTF-8 ANSI codepage (e.g. zh-CN CP-936/GBK), UTF-8 bytes in server.json description fields can be silently reinterpreted through the system codepage, producing invalid JSON with lone surrogate characters (e.g. \udc94). This adds validatePublishData() that checks both valid UTF-8 encoding and absence of JSON-escaped lone surrogates (\udc00-\udfff) before transmitting the publish or validate request. If corruption is detected, the command fails with a clear error message suggesting a workaround. Fixes modelcontextprotocol#1306 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
Hey, @hiro-nikaitou, thanks for the contribution but there was another PR already opened (#1310) and it was fair to go with it! Anyway, the issue is now addressed so with the next release it would be available to everyone! Thanks again! |
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.
Summary
On Windows systems running under Git Bash/MSYS with a non-UTF-8 ANSI codepage (e.g. zh-CN CP-936/GBK), UTF-8 bytes in
server.jsondescription fields can be silently reinterpreted through the system codepage. The result is corrupted metadata in the registry containing lone surrogate characters (e.g.\udc94).This adds a
validatePublishData()function that checks both valid UTF-8 encoding and absence of JSON-escaped lone surrogates (\udc00-\udfff) before transmitting the publish or validate request. If corruption is detected, the command fails with a clear error message suggesting running from PowerShell or CMD instead of Git Bash.Changes
validatePublishData()function and call before HTTP sendvalidatePublishData()call invalidateViaAPIfor consistencyTesting
go build ./cmd/publisher/...passesgo vet ./cmd/publisher/commands/passesFixes #1306