Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I thought this would happen only to others...

I thought this would happen only to others...

Scheduled Pinned Locked Moved The Lounge
help
11 Posts 7 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nicolas Dorier
    wrote on last edited by
    #1

    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:

    L S N V 4 Replies Last reply
    0
    • N Nicolas Dorier

      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:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Might be worth checking Welsh (cy-GB) too.. :) Welsh Alphabet[^]

      How do you know so much about swallows? Well, you have to know these things when you're a king, you know.

      1 Reply Last reply
      0
      • N Nicolas Dorier

        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:

        S Offline
        S Offline
        szukuro
        wrote on last edited by
        #3

        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...

        N 1 Reply Last reply
        0
        • N Nicolas Dorier

          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:

          N Offline
          N Offline
          Nagy Vilmos
          wrote on last edited by
          #4

          And CCS is actually two CS's not a C and CS. There are over forty characters in the Hungarian Alphabet and a fair few are dipthongs, with evan a three letter letter one as well - clickity[^]

          veni bibi saltavi

          1 Reply Last reply
          0
          • S szukuro

            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...

            N Offline
            N Offline
            Nicolas Dorier
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • N Nicolas Dorier

              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:

              V Offline
              V Offline
              Vark111
              wrote on last edited by
              #6

              Clearly, the solution is to keep Hungarians away from computers.

              J N 2 Replies Last reply
              0
              • V Vark111

                Clearly, the solution is to keep Hungarians away from computers.

                J Offline
                J Offline
                Jorgen Andersson
                wrote on last edited by
                #7

                And Gin.

                Wrong is evil and must be defeated. - Jeff Ello

                C N 2 Replies Last reply
                0
                • V Vark111

                  Clearly, the solution is to keep Hungarians away from computers.

                  N Offline
                  N Offline
                  Nicolas Dorier
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • J Jorgen Andersson

                    And Gin.

                    Wrong is evil and must be defeated. - Jeff Ello

                    C Offline
                    C Offline
                    Corporal Agarn
                    wrote on last edited by
                    #9

                    I would have to sell my stock!

                    Mongo: Mongo only pawn... in game of life.

                    1 Reply Last reply
                    0
                    • J Jorgen Andersson

                      And Gin.

                      Wrong is evil and must be defeated. - Jeff Ello

                      N Offline
                      N Offline
                      Nagy Vilmos
                      wrote on last edited by
                      #10

                      :mad:

                      veni bibi saltavi

                      J 1 Reply Last reply
                      0
                      • N Nagy Vilmos

                        :mad:

                        veni bibi saltavi

                        J Offline
                        J Offline
                        Jorgen Andersson
                        wrote on last edited by
                        #11

                        ;P

                        Wrong is evil and must be defeated. - Jeff Ello

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups