Bug 316666 (MONO70478) - String.Compare("HIJ", "hij", false) gives wrong result
Summary: String.Compare("HIJ", "hij", false) gives wrong result
Status: RESOLVED FIXED
Alias: MONO70478
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Atsushi Enomoto
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-12 02:04 UTC by Ben Maurer
Modified: 2007-09-15 21:24 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:01:22 UTC


---- Reported by bmaurer@users.sf.net 2004-12-11 19:04:22 MST ----

[benm@omega benm]$ cat t.cs
using System;
  
class X {
        static void Main ()
        {
              Console.WriteLine (String.Compare("HIJ", "hij", false));
        }
}
[benm@omega benm]$ mcs t.cs
[benm@omega benm]$ mono t.exe
-1

On MSFT:

C:\Inetpub\ftproot>t
1

C:\Inetpub\ftproot>



---- Additional Comments From mdevine@cs.stanford.edu 2005-05-12 22:18:15 MST ----

I hunted this down through several layers of code, until I found
string_invariant_compare_char in mono/mono/metadata/locales.c.  Here's
an excerpt:

	if (options & CompareOptions_IgnoreCase) {
             ...
	} else {
		/*
		 * No options. Kana, symbol and spacing options don't
		 * apply to the invariant culture.
		 */

		/*
		 * FIXME: here we must use the information from c1type and c2type
		 * to find out the proper collation, even on the InvariantCulture, the
		 * sorting is not done by computing the unicode values, but their
		 * actual sort order.
		 */
		result = (gint32) c1 - c2;
	}

I believe that this FIXME is the source of this problem.  I'm not sure
about unicode, but in ANSI, lowercase letters are numerically lower
than uppercase.  In this code then, if we are not ignoring case while
comparing, we simply subtract the bit patterns.



---- Additional Comments From atsushi@ximian.com 2005-05-12 23:30:23 MST ----

Anyways I am going to "fix" those collation bugs by replacing icu with
another implementation.



---- Additional Comments From atsushi@ximian.com 2005-09-27 07:03:28 MST ----

Now managed collation is default, so this is fixed in svn.


Unknown operating system unknown. Setting to default OS "Other".