fix(candid_parser): escape service type method names in the Rust binding + release candid_parser 0.4.1 - #759
Merged
Conversation
…ing + release candid_parser 0.4.1 Patch release. `pp_ty_service` emitted the method names of a service type into a Rust string literal without escaping them, so a name containing characters that are legal in Candid text but significant in Rust produced incorrect output. They now go through `escape_debug`, matching `pp_function` and the `#[serde(rename)]` attributes. See CHANGELOG. Output is byte-identical for names that are ordinary identifiers, so no existing goldenfile changed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a Rust-binding code generation correctness/security issue by properly escaping service type method names before emitting them into Rust string literals, and ships it as a candid_parser patch release.
Changes:
- Escape service type method names in the Rust binding via
escape_debug()so generated Rust stays syntactically valid and non-injectable. - Add a dedicated
.didasset plus structural Rust tests (viasyn) to ensure escaping happens and output shape is unaffected. - Release bump to
candid_parser 0.4.1with corresponding lockfile and changelog updates.
Reviewed changes
Copilot reviewed 9 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rust/candid_parser/src/bindings/rust.rs | Escapes service type method names before embedding them into Rust string literals. |
| rust/candid_parser/tests/test_rust_bindings.rs | New structural tests validating generated Rust remains well-formed and escaped names are preserved. |
| rust/candid_parser/tests/parse_type.rs | Adds the new escape-focused asset to the Motoko-backend “expected error” list. |
| rust/candid_parser/tests/assets/service_method_escape.did | New test asset covering method names requiring escaping (quotes, backslashes, control chars, comment markers). |
| rust/candid_parser/tests/assets/ok/service_method_escape.rs | New golden output for Rust backend demonstrating correct escaping in define_service!. |
| rust/candid_parser/tests/assets/ok/service_method_escape.js | New golden output for JS backend for the same asset. |
| rust/candid_parser/tests/assets/ok/service_method_escape.did | New golden pretty-printed .did output for the asset. |
| rust/candid_parser/tests/assets/ok/service_method_escape.d.ts | New golden output for TS declarations backend for the asset. |
| rust/candid_parser/Cargo.toml | Bumps version to 0.4.1 and adds syn as a dev-dependency for the new tests. |
| CHANGELOG.md | Documents the candid_parser 0.4.1 fix and its security implications. |
| Cargo.lock | Updates lockfile entries for candid_parser 0.4.1 and adds syn to the dependency graph. |
| rust/bench/Cargo.lock | Updates bench lockfile to use candid_parser 0.4.1. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
lwshang
marked this pull request as ready for review
August 13, 2026 17:34
|
✅ No security or compliance issues detected. Reviewed everything up to 8b85aa3. Security Overview
Detected Code Changes
|
adamspofford-dfinity
approved these changes
Aug 14, 2026
3 tasks
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.
Patch release. The Rust binding emitted the method names of a service type into a string literal without escaping them, so a name containing characters that are legal in Candid text but significant in Rust produced incorrect output. They now go through
escape_debug, matchingpp_functionand the#[serde(rename)]attributes, which already escaped. See CHANGELOG.Output is byte-identical for names that are ordinary identifiers, so no existing goldenfile changed.
Tests: a new
service_method_escape.didasset covers the characters that need escaping across all backends, andtests/test_rust_bindings.rsasserts the generated Rust has the same item structure as an equivalent service with plain names. Both fail onmaster.The JS/TS bindings needed no change — they route names through
candid::pretty::utils::quote_ident, which already escapes.🤖 Generated with Claude Code