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

VB -> C#: = "" should not be converted to string.IsNullOrEmpty when Option Compare Text #1089

Open
tats-u opened this issue Apr 6, 2024 · 0 comments
Labels
output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion

Comments

@tats-u
Copy link

tats-u commented Apr 6, 2024

VB.Net input code

Option Compare Text
Imports System
Imports Microsoft.VisualBasic

Public Class VisualBasicClass
    Public Shared Sub Main()
        Dim s = ChrW(&H2060) & ChrW(&H2060)
        Console.WriteLine(s = "")
        Console.WriteLine(s = Nothing)
    End Sub
End Class

https://sharplab.io/#v2:DYLgbgRgNALiBOBXAdgHwPIAcYEsD2yABAMJ4C2mAhvAKaEAqNAHjALABQAkhXvDAM6EAygE9+MGmQ7dMvAYQCyOAMbw8/PADMYAOgBqOfokrAAQpX4qOHAAqIIwFSWAXBBoyfOXlxF/34chEGEdg5OQgAW1DQAJsL2ipQ4yAAUAJSBwVkAIjhkhIIAvCQR8ADqKQBkABIATAAMAGz1aYSVJeVVdU0tmVlBpMgawDQ6ZfA4EgAyyTQpRYQARIsZ7P3Bg8Oj45M0M8hzCwByeDARyQDmq1kAoshxQvYcd3G+rkA==

True
False

Erroneous output

using Microsoft.VisualBasic; // Install-Package Microsoft.VisualBasic
using Microsoft.VisualBasic.CompilerServices; // Install-Package Microsoft.VisualBasic

public partial class VisualBasicClass
{
    public static void Main()
    {
        string s = Conversions.ToString(Strings.ChrW(0x2060)) + Strings.ChrW(0x2060);
        Console.WriteLine(string.IsNullOrEmpty(s));
        Console.WriteLine(string.IsNullOrEmpty(s));
    }
}
False
False

Expected output

using Microsoft.VisualBasic; // Install-Package Microsoft.VisualBasic
using Microsoft.VisualBasic.CompilerServices; // Install-Package Microsoft.VisualBasic

public partial class VisualBasicClass
{
    public static void Main()
    {
        string s = Conversions.ToString(Strings.ChrW(0x2060)) + Strings.ChrW(0x2060);
        Console.WriteLine(Operators.CompareString(s, "", true));
        Console.WriteLine(string.IsNullOrEmpty(s));
    }
}

Details

Strings composed of invisible characters (e.g. U+2060 and IVS (e.g. U+E0100)) are treated as equivalent to the empty string by VB only when Option Compare Text.
they are always told from null.

@tats-u tats-u added the VB -> C# Specific to VB -> C# conversion label Apr 6, 2024
@tats-u tats-u changed the title VB -> C#: _Add a short description_ VB -> C#: = "" should not be converted to string.IsNullOrEmpty when Option Compare Text Apr 6, 2024
@GrahamTheCoder GrahamTheCoder added the output logic error A bug where the converted output behaves differently to the input code label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants