I thought this would happen only to others...
-
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu");
string mechanism = "HMACSHA256";
var v1 = mechanism.StartsWith("HMAC");mechanism = "HMAC-SHA256";
var v2 = mechanism.StartsWith("HMAC");Result : v1 is false, but v2 is true. I was too lazy for using StringComparison.Ordinal, since, in my code all the strings were hardcoded... No way, ever, a bug would happen... Until an hungarian used it. Apparently, if you are hungarian, "CS" is counted as 1 letter, BUT in unicode this is 2 letters... :doh:
-
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu");
string mechanism = "HMACSHA256";
var v1 = mechanism.StartsWith("HMAC");mechanism = "HMAC-SHA256";
var v2 = mechanism.StartsWith("HMAC");Result : v1 is false, but v2 is true. I was too lazy for using StringComparison.Ordinal, since, in my code all the strings were hardcoded... No way, ever, a bug would happen... Until an hungarian used it. Apparently, if you are hungarian, "CS" is counted as 1 letter, BUT in unicode this is 2 letters... :doh:
-
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu");
string mechanism = "HMACSHA256";
var v1 = mechanism.StartsWith("HMAC");mechanism = "HMAC-SHA256";
var v2 = mechanism.StartsWith("HMAC");Result : v1 is false, but v2 is true. I was too lazy for using StringComparison.Ordinal, since, in my code all the strings were hardcoded... No way, ever, a bug would happen... Until an hungarian used it. Apparently, if you are hungarian, "CS" is counted as 1 letter, BUT in unicode this is 2 letters... :doh:
Yes, Hungarian has a few letters that are 2 characters long and one that is 3. So depending on culture settings this can get taken into account (same for SQL Server etc.). Unfortunately, as with other culture or datetime related problems there are weird corner cases. For example the word "pácsó" (meaning curing salt) consists of two parts, "pác" and "só", so even though c and s are next to each other they are two different letters and pronounced as such. Needless to say the computer has no way of knowing this, so
StartsWith("pác")
returns false for "hu" culture setting, which strictly speaking is incorrect. Cultures are hard... -
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu");
string mechanism = "HMACSHA256";
var v1 = mechanism.StartsWith("HMAC");mechanism = "HMAC-SHA256";
var v2 = mechanism.StartsWith("HMAC");Result : v1 is false, but v2 is true. I was too lazy for using StringComparison.Ordinal, since, in my code all the strings were hardcoded... No way, ever, a bug would happen... Until an hungarian used it. Apparently, if you are hungarian, "CS" is counted as 1 letter, BUT in unicode this is 2 letters... :doh:
-
Yes, Hungarian has a few letters that are 2 characters long and one that is 3. So depending on culture settings this can get taken into account (same for SQL Server etc.). Unfortunately, as with other culture or datetime related problems there are weird corner cases. For example the word "pácsó" (meaning curing salt) consists of two parts, "pác" and "só", so even though c and s are next to each other they are two different letters and pronounced as such. Needless to say the computer has no way of knowing this, so
StartsWith("pác")
returns false for "hu" culture setting, which strictly speaking is incorrect. Cultures are hard...Cultures are hard...
Well, at this point I see no reason over not using StringComparison.InvariantCulture/CultureInfo.InvariantCulture in any code. In fact, this should be the default.
-
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu");
string mechanism = "HMACSHA256";
var v1 = mechanism.StartsWith("HMAC");mechanism = "HMAC-SHA256";
var v2 = mechanism.StartsWith("HMAC");Result : v1 is false, but v2 is true. I was too lazy for using StringComparison.Ordinal, since, in my code all the strings were hardcoded... No way, ever, a bug would happen... Until an hungarian used it. Apparently, if you are hungarian, "CS" is counted as 1 letter, BUT in unicode this is 2 letters... :doh:
-
And Gin.
Wrong is evil and must be defeated. - Jeff Ello
-
Well, the problem is that even if you try to do it with this code :
if(Thread.CurrentThread.CurrentCulture.ToString().StartWith("hu"))
{
throw new HttpException("Not authorized");
}You are not even sure it will works correctly. :D
-
And Gin.
Wrong is evil and must be defeated. - Jeff Ello
I would have to sell my stock!
Mongo: Mongo only pawn... in game of life.
-
And Gin.
Wrong is evil and must be defeated. - Jeff Ello
:mad:
veni bibi saltavi
-
:mad:
veni bibi saltavi
;P
Wrong is evil and must be defeated. - Jeff Ello