Escape Unicode line separators in CSharpHelper string and char literals - #38711
Open
ilkertskn wants to merge 2 commits into
Open
Escape Unicode line separators in CSharpHelper string and char literals#38711ilkertskn wants to merge 2 commits into
ilkertskn wants to merge 2 commits into
Conversation
- Escape U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR) and U+0085 (NEXT LINE) using their backslash-u escape sequences in Literal(string) and Literal(char) - The C# compiler treats these code points as new-line characters, so emitting them raw produced generated code that failed to compile (CS1010: Newline in constant) - Add tests covering the three separators for both string and char literals
Contributor
Author
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR fixes a code-generation edge case in CSharpHelper where certain Unicode newline code points (U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, U+0085 NEXT LINE) could be emitted unescaped inside string/char literals, causing generated C# to fail compilation (e.g. CS1010 “Newline in constant”).
Changes:
- Escape U+2028, U+2029, and U+0085 via
\uXXXXsequences when emitting C# string literals inCSharpHelper.Literal(string). - Escape the same code points when emitting C# char literals in
CSharpHelper.Literal(char). - Add design-time tests covering these characters for both string and char literal emission.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/EFCore.Design/Design/Internal/CSharpHelper.cs | Adds escaping for Unicode newline code points in string and char literal generation. |
| test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs | Adds regression tests asserting the escaped \uXXXX output for string and char literals. |
Comments suppressed due to low confidence (2)
src/EFCore.Design/Design/Internal/CSharpHelper.cs:410
- In Literal(char), consider using character literals ('\u2028', etc.) in the switch patterns for clarity instead of numeric casts.
(char)0x2028 => "\\u2028",
(char)0x2029 => "\\u2029",
(char)0x0085 => "\\u0085",
test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs:92
- Test name says "line and paragraph separators" but the test also covers U+0085 (NEXT LINE). Rename to reflect that these are all Unicode newline characters.
public void Literal_escapes_unicode_line_and_paragraph_separators_in_char()
Comment on lines
+367
to
+369
| .Replace(((char)0x2028).ToString(), "\\u2028") | ||
| .Replace(((char)0x2029).ToString(), "\\u2029") | ||
| .Replace(((char)0x0085).ToString(), "\\u0085") |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.