Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Escape characters in diffable cs field default values #386

Merged
merged 3 commits into from
Dec 8, 2024

Conversation

MrUser127
Copy link
Contributor

@MrUser127 MrUser127 commented Dec 6, 2024

System.Globalization.CharUnicodeInfo is supposed to look like this:

public static class CharUnicodeInfo
{
internal const char HIGH_SURROGATE_START = '\ud800';
internal const char HIGH_SURROGATE_END = '\udbff';
internal const char LOW_SURROGATE_START = '\udc00';
internal const char LOW_SURROGATE_END = '\udfff';

and in DiffableCsOutputFormat.cs line 184 those default values are characters, not strings

if (defaultValue is string stringDefaultValue)
sb.Append('"').Append(stringDefaultValue).Append('"');
else
sb.Append(defaultValue); // it tries to do this, but it cant be encoded

public static class CharUnicodeInfo
{
internal const char HIGH_SURROGATE_START = �;
internal const char HIGH_SURROGATE_END = �;
internal const char LOW_SURROGATE_START = �;
internal const char LOW_SURROGATE_END = �;

Unhandled exception. System.Text.EncoderFallbackException: Unable to translate Unicode character \uD800 at index 119 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown, Int32 index)
at System.Text.Encoding.GetBytesWithFallback(ReadOnlySpan1 chars, Int32 originalCharsLength, Span1 bytes, Int32 originalBytesLength, EncoderNLS encoder, Boolean throwForDestinationOverflow)
at System.Text.Encoding.GetBytesWithFallback(Char* pOriginalChars, Int32 originalCharCount, Byte* pOriginalBytes, Int32 originalByteCount, Int32 charsConsumedSoFar, Int32 bytesWrittenSoFar, EncoderNLS encoder)
at System.IO.File.WriteToFile(String path, FileMode mode, ReadOnlySpan`1 contents, Encoding encoding)
at System.IO.File.WriteAllText(String path, String contents)
at Cpp2IL.Core.OutputFormats.DiffableCsOutputFormat.DoOutput(ApplicationAnalysisContext context, String outputRoot) in Cpp2IL.Core\OutputFormats\DiffableCsOutputFormat.cs:line 46
at Cpp2IL.Program.MainWithArgs(Cpp2IlRuntimeArgs runtimeArgs) in Cpp2IL\Program.cs:line 613
at Cpp2IL.Program.Main(String[] args) in Cpp2IL\Program.cs:line 531

@ds5678
Copy link
Contributor

ds5678 commented Dec 6, 2024

This feels like a hack. Ideally, your pr would fix the underlying issue.

How about you post the stack trace you encountered and information about how it can be reproduced.

@MrUser127 MrUser127 changed the title Fix diffable cs failing to write \\uD800 in CharUnicodeInfo Escape characters in diffable cs field default values Dec 7, 2024
@SamboyCoding SamboyCoding merged commit 9c6a962 into SamboyCoding:development Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants