dotnet / dotnet/csharpstandard

String interpolation doesn't allow bracket escapes in format string

Open
#986 14 comments 1 reaction 1 assignee Claimed by @Nigel-Ecma View on GitHub
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

**Describe the bug**
Roslyn no longer allows bracket escapes in format strings as of version 4.4.0-6.22561.11 (1ce8866c), inconsistent with the specification

```
Regular_Interpolation_Format
: ':' Interpolated_Regular_String_Element+
;

fragment Interpolated_Regular_String_Element
: Interpolated_Regular_String_Character
| Simple_Escape_Sequence
| Hexadecimal_Escape_Sequence
| Unicode_Escape_Sequence
| Open_Brace_Escape_Sequence
| Close_Brace_Escape_Sequence
;
```

**Example**

```csharp
using static System.Console;
WriteLine($"{1:a{{}");
WriteLine($"{1:{{b}");
WriteLine($"{1:a{{b}");
WriteLine($"{1:a}}b}");
WriteLine($"{1:{{a}");
```
https://sharplab.io/#v2:CYLg1APgAgDABFAjANgYgdAYQPYDsDO2ANgKYDcAsAFADqATgJYAuJAMg7iQBQAkARAG9EIAIYCBAXz4BKSrUYt2nXoOHiARlNnV6zNh278hojVrm7FBlcZESJmmeYX7lRtQNuOgA===

**Expected behavior**
Remove escape sequences from the format string

**Additional context**
The code was valid before and some time during .NET 6's development but is no longer valid in .NET 6 because of a breaking change introduced in https://github.com/dotnet/roslyn/pull/57751

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.