Browse Source

Allow explicit null termination character

pull/3380/head
ds5678 3 months ago committed by Siegfried Pammer
parent
commit
3a13d5a698
  1. 1
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  2. 8
      ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

1
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -447,6 +447,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -447,6 +447,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
#endif
#if CS110 && !NET40
public static ReadOnlySpan<byte> UTF8Literal => "Hello, world!"u8;
public static ReadOnlySpan<byte> UTF8LiteralWithNullTerminator => "Hello, world!\0"u8;
#endif
#endregion

8
ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

@ -182,9 +182,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -182,9 +182,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms
for (int i = 0; i < size; i++)
{
byte val = blob.CurrentPointer[i];
// If the string has control characters, it's probably binary data and not a string.
if (val < 0x20 && val is not ((byte)'\r' or (byte)'\n' or (byte)'\t'))
if (val == 0 && i == size - 1 && size > 1)
{
// Allow explicit null-termination character.
}
else if (val < 0x20 && val is not ((byte)'\r' or (byte)'\n' or (byte)'\t'))
{
// If the string has control characters, it's probably binary data and not a string.
text = null;
return false;
}

Loading…
Cancel
Save