Skip to content

Issue with QuoteSnippetStringCStyle when parsing '\u0085' character #1740

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
hamarb123 opened this issue Jan 15, 2020 · 5 comments
Closed

Issue with QuoteSnippetStringCStyle when parsing '\u0085' character #1740

hamarb123 opened this issue Jan 15, 2020 · 5 comments

Comments

@hamarb123
Copy link
Contributor

Another line needs to be added after this, which would be

case '\u0085':

This is because it is recognised as a newline character in C# (see here), which cannot be in literal strings.
If the CSharpCodeGenerator class was used to make code with a string in it that has U+0085 in it, it would generate invalid C# code.
NB: this is also an issue on the .NET Framework (see here)

I would like to implement this change, thanks!

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jan 15, 2020
@GrabYourPitchforks GrabYourPitchforks added this to the 5.0 milestone Jan 16, 2020
@GrabYourPitchforks
Copy link
Member

Thanks for reporting this! Your reasoning seems sound to me. Feel free to look through our contribution guidelines then send a PR with your proposed fix. Remember also to update any appropriate unit tests to validate your change

@hamarb123
Copy link
Contributor Author

hamarb123 commented Jan 17, 2020

@GrabYourPitchforks, what sort of a test would I need, a test that checks if a class with a string in it has the correct contents when the string has newline characters in it? Also, where should I put the test? Maybe in here?
Like this:

[Fact]
public void SpecialNewLineCharactersInStringsDoneCorrectly()
{
    var cd = new CodeTypeDeclaration("ClassWithStringFields") { IsClass = true };

    var field = new CodeMemberField("System.String", "StringWithSpecialNewLines");
    field.Attributes = MemberAttributes.Public | MemberAttributes.Static;
    field.InitExpression = new CodePrimitiveExpression("\u0085\u2028\u2029");
    cd.Members.Add(field);

    AssertEqual(cd,
        @"public class ClassWithStringFields {
              public static string StringWithSpecialNewLines = ""\u0085\u2028\u2029"";
          }");
 }

Is there anything that I should rename?
Thank you.

@GrabYourPitchforks
Copy link
Member

That looks like a fine test. The area owners might have further feedback regarding naming once you submit the PR.

@hamarb123
Copy link
Contributor Author

The PR is at #1853

stephentoub pushed a commit that referenced this issue Jan 23, 2020
#1740) (#1853)

* Fix for issue #1740

U+0085 not recognised as a newline character in CSharpCodeGenerator.cs

Fix $1740

* Fix for issue #1740

U+0085 not recognised as a newline character in CSharpCodeGenerator.cs

* Fix for issue #1740

U+0085 not recognised as a newline character in CSharpCodeGenerator.cs
This change fixes a previous test that incorrectly causes the character to be forced out of being in unicode format.

* Stop the changes from #1740 on the .Net Framework as per #1913

Read #1913 for why, view PR #1853 and #1740 also.
@hamarb123
Copy link
Contributor Author

This has now been solved, see PR #1853.

@jeffhandley jeffhandley removed the untriaged New issue has not been triaged by the area owner label Sep 17, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

5 participants