Skip to content

Comments

Fix invalid JSON from unescaped backslashes in MQL5 string serialization#294

Open
biohazardxxx wants to merge 11 commits intovdemydiuk:devfrom
biohazardxxx:fix/mql5-json-string-escaping
Open

Fix invalid JSON from unescaped backslashes in MQL5 string serialization#294
biohazardxxx wants to merge 11 commits intovdemydiuk:devfrom
biohazardxxx:fix/mql5-json-string-escaping

Conversation

@biohazardxxx
Copy link

Summary

  • JSONString.toString() in mq5/json.mqh emitted raw strings without escaping special characters. When MQL5 functions returned Windows paths (e.g. TerminalInfoString), unescaped backslashes produced invalid JSON, causing JsonReaderException: Bad JSON escape sequence on the C# client side.
  • Added proper JSON escaping for backslash, double-quote, newline, carriage return, and tab characters during serialization.
  • The MQL4 json.mqh has the same latent bug but is worked around by a manual StringReplace in Execute_TerminalInfoString; this fix addresses it at the serialization layer for MQL5.

Test plan

  • Compile MtApi5.mq5 with MetaEditor to verify MQL5 compilation succeeds
  • Connect a .NET client and call TerminalInfoString with path-returning properties (e.g. TERMINAL_PATH, TERMINAL_DATA_PATH) — verify valid JSON is returned and parsed without exceptions
  • Verify strings containing quotes, newlines, and tabs are also correctly escaped in JSON output

🤖 Generated with Claude Code

vdemydiuk and others added 11 commits July 28, 2025 23:29
JSONString.toString() in mq5/json.mqh emitted raw strings without
escaping special characters. When MQL5 functions returned Windows paths
(e.g. TerminalInfoString), backslashes produced invalid JSON causing
JsonReaderException on the C# client side.

Escape backslash, double-quote, newline, carriage return, and tab
characters during serialization, matching the JSON spec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@biohazardxxx biohazardxxx changed the base branch from master to dev February 19, 2026 11:53
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.

2 participants