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
Quoted default values aren't escaped: a " or \ in DefaultValue generates C# that doesn't compile #111
TemplateBase.WriteDefaultValueTo (CodeBlocker/Templates/TemplateBase.cs:96) wraps the value as $"\"{DefaultValue}\"" when DefaultValueIsQuoted is set, without escaping it. This affects FieldTemplate, ParameterTemplate, PropertyTemplate and EnumMemberTemplate.
Even without the quote, \t would silently become a tab.
Expected output: private string p = "C:\\temp\\\"x\"";
Why it matters
DefaultValueIsQuoted exists so callers can pass a raw string value, and the obvious inputs for it are paths, regexes, JSON snippets and messages containing quotes. Each of these produces broken or silently altered generated code. In a source generator the result is a compile error in the consumer's project, far from the cause.
Suggested fix / acceptance criteria
Escape \, ", \r, \n, \t, \0 and other control characters (\uXXXX) before quoting. Alternatively, use SymbolDisplay.FormatLiteral(value, quote: true) if taking a Roslyn dependency is acceptable, or emit a verbatim @"..." literal with " doubled.
Add tests with a backslash, a quote, and a newline in DefaultValue, each asserting the literal round-trips.
Priority: High. Ordinary inputs to DefaultValueIsQuoted, such as paths, regexes and messages that contain quotes, produce C# that doesn't compile, or that silently changes the value (\t becomes a tab). In a source generator the error lands in the consumer's project, far from its cause.
Area / suggested assignee:TemplateBase.WriteDefaultValueTo, which affects the Field, Parameter, Property and EnumMember templates. Maintainer: @matt-edmondson.
Next steps: Escape \, ", \r, \n, \t, \0 and other control characters (\uXXXX) before quoting. If a Roslyn dependency is acceptable, SymbolDisplay.FormatLiteral(value, true) does this. Add round-trip tests with a backslash, a quote and a newline.
Activity
matt-edmondson commentedon Sep 26, 2026
Triage
DefaultValueIsQuoted, such as paths, regexes and messages that contain quotes, produce C# that doesn't compile, or that silently changes the value (\tbecomes a tab). In a source generator the error lands in the consumer's project, far from its cause.TemplateBase.WriteDefaultValueTo, which affects the Field, Parameter, Property and EnumMember templates. Maintainer: @matt-edmondson.\,",\r,\n,\t,\0and other control characters (\uXXXX) before quoting. If a Roslyn dependency is acceptable,SymbolDisplay.FormatLiteral(value, true)does this. Add round-trip tests with a backslash, a quote and a newline.Generated by Claude Code