You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[http-client-python][ICM] Escape quotes and backslashes in StringType.get_declaration #12405
This only special-cases when the entire string is a single " character. If a string literal in TypeSpec (such as a parameter/property default value, constant, enum value, or discriminator value) contains embedded double quotes ("), backslashes (\), or newlines, the emitted Python string literal in _models.py / _enums.py is unescaped and produces invalid Python syntax or unintended escape sequences.
String literals emitted into generated Python source files should properly escape embedded backslashes, quotes, and control characters so that any valid TypeSpec string literal produces valid, round-trippable Python source code.
Proposed Fix
Update StringType.get_declaration in primitive_types.py (and string literal formatting in model_type.py / model_serializer.py) to escape backslashes and quotes (e.g., via json.dumps(str(value))) and add unit tests covering string literals with embedded quotes and backslashes.
🎯 Issue Triage
The Python client emitter does not safely encode TypeSpec string values before embedding them in generated Python source, which can produce invalid syntax or alter backslash/control-character semantics. Category: Bug Area: emitter:client:python
⚠️ No reproduction provided. A minimal repro would help diagnose this issue.
🔍 Analysis
The affected paths are Python source generation for literal/default/enum values and model discriminator or wire-name metadata. The apparent cause is direct interpolation into quoted Python literals without a shared escaping routine. Related reports #10784 and #11881 concern escaping in generated docstrings, but they use different rendering paths and are not duplicates of this value-serialization defect.
📝 Suggested next steps
Add a minimal TypeSpec model or operation covering embedded quotes, backslashes, and a control character.
Centralize Python string-literal serialization and use it at each identified interpolation site.
Add generated-source syntax and round-trip regression tests for defaults, enum values, discriminators, and wire names.
changed the title [-][http-client-python] Escape quotes and backslashes in StringType.get_declaration[/-][+][http-client-python][ICM] Escape quotes and backslashes in StringType.get_declaration[/+]on Oct 29, 2026
Activity
github-actions commentedon Oct 26, 2026
🎯 Issue Triage
The Python client emitter does not safely encode TypeSpec string values before embedding them in generated Python source, which can produce invalid syntax or alter backslash/control-character semantics.
Category: Bug
Area:
emitter:client:python🔍 Analysis
The affected paths are Python source generation for literal/default/enum values and model discriminator or wire-name metadata. The apparent cause is direct interpolation into quoted Python literals without a shared escaping routine. Related reports #10784 and #11881 concern escaping in generated docstrings, but they use different rendering paths and are not duplicates of this value-serialization defect.
📝 Suggested next steps
[-][http-client-python] Escape quotes and backslashes in StringType.get_declaration[/-][+][http-client-python][ICM] Escape quotes and backslashes in StringType.get_declaration[/+][http-client-python][ICM] Escape generated string literals and wire n…
msyyc commentedon Nov 5, 2026
fixed in #12342