[Mono-bugs] [Bug 687444] New: String.Compare incompatible with .net on strings ending with '\0'

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Apr 14 02:59:36 EDT 2011



           Summary: String.Compare incompatible with .net on strings
                    ending with '\0'
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: x86-64
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: nicklas at isharp.dk
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

Created an attachment (id=424862)
 --> (http://bugzilla.novell.com/attachment.cgi?id=424862)
Patch to corlib test-suite that shows the issue

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16
(KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16

I discovered a bug in String.Compare when using a UTF8 string created
from a byte array with a zero-byte at the end. It's converted to the
same string on both .net and mono, however, String.Compare on .net is
different from String.Compare on mono.

The issue is the following:

Mono reports "1" on the string compare, signaling that the converted
string is "larger" than the hard-coded string I compare it to. And it
kinda is - the byte array is converted to "%EOF\0" and the hardcoded
string is just "%EOF" - but .net manages to ignore the '\0' when doing
the compare, which results in "0" (equal strings).

Attached is a patch, which adds a test-case to
'mcs/class/corlib/Test/System' which shows the issue -
"CompareNotWorking3" to follow the lingo :)

I have tried to track the issue down myself in String.Compare, but I
gave up due to the complexity of the underlying code.

As a final note, I'm running with UTF8 culture on my Linux box, where
the issue is showing up.

Reproducible: Always

Steps to Reproduce:
Create a test-program with the following code:

byte [] theBytes = new byte[5] {37, 69, 79, 70, 0};
// this call returns "%EOF\0" on both win and mono
string theStr = System.Text.Encoding.UTF8.GetString(theBytes, 0, 5);
string theRealStr = "%EOF";
//should be 0, mono returns 1
string.Compare(theStr, theRealStr);

Actual Results:  
Mono returns 1

Expected Results:  
MS .net on windows server 2008 r2 returns 0 - so to be compatible with MS, mono
should also return 0.

Running ArchLinux, kernel 2.6.37 with English(Denmark) locale on UTF8

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list