FIX: Update escaping rules in connection string parser and builder by saurabh500 · Pull Request #364 · microsoft/mssql-python

Pull request overview

This PR fixes the ODBC connection string escaping rules in the parser and builder to correctly align with the MS-ODBCSTR specification. The key issue was that the code was treating {{ as an escape sequence for {, when in fact only closing braces } need escaping (as }}). Opening braces { should be kept as literal characters within braced values.

Key Changes:

  • Updated parser to not treat {{ as an escape sequence, keeping it as literal {{
  • Updated builder to only escape closing braces }}}, removed escaping of opening braces
  • Updated all affected tests to reflect the corrected behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
mssql_python/connection_string_parser.py Removed logic that treated {{ as an escape sequence in _parse_braced_value(), updated comments and docstrings to clarify only } needs escaping
mssql_python/connection_string_builder.py Removed .replace("{", "{{") from _escape_value(), updated docstrings and examples to reflect only closing braces need escaping
tests/test_010_connection_string_parser.py Updated test assertions and docstrings to expect {{ as literal characters rather than escaped {, covering multiple test cases including edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.