IE 6 Question Mark Wierdness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Cowper

    IE 6 Question Mark Wierdness


    Anyone come across anything like this before? This is some javascript
    validation of user input.

    If ch is a question mark character, the test passes and false is
    returned.

    if ((ch==">") || (ch=="<") || (ch=="\\") ||
    (ch=="|") || (ch=="\"") || (ch=="¦")) {

    return false;
    }

    The problem is that the character '¦' is testing as equal to '?'. This
    character is Latin 1 A6.

    if ("?"=="¦") { alert("Holy Smoke!"); }

    It seems to only happen on IE6 (I've tried 6.0.2800.1106).
    Anyone got any thoughts?

    Thanks
    Andrew Cowper

    --
    Pick a different user name to email me.
  • asdf asdf

    #2
    Re: IE 6 Question Mark Wierdness

    Hello, although I can't reproduce your problem, I'd like to suggest
    that you could use a hash table to perform the checks.

    var map = new Object();
    map[">"] = true;
    map["|"] = true;
    ..
    ..
    ..

    if (map[input]) return found_in_map;

    Comment

    • Douglas Crockford

      #3
      Re: IE 6 Question Mark Wierdness

      > Hello, although I can't reproduce your problem, I'd like to suggest[color=blue]
      > that you could use a hash table to perform the checks.
      >
      > var map = new Object();
      > map[">"] = true;
      > map["|"] = true;
      > ....
      > if (map[input]) return found_in_map;[/color]

      This is a good place to use the object literal notation.

      var map = {'>': true, '|': true, ...};
      ...
      return map[input];



      Comment

      • Greg

        #4
        Re: IE 6 Question Mark Wierdness

        Andrew Cowper <junk.mail@bloa t.plus.com> wrote in message news:<87fziy81r v.fsf@bloat.plu s.com>...[color=blue]
        > Anyone come across anything like this before? This is some javascript
        > validation of user input.
        >
        > If ch is a question mark character, the test passes and false is
        > returned.
        >
        > if ((ch==">") || (ch=="<") || (ch=="\\") ||
        > (ch=="|") || (ch=="\"") || (ch=="¦")) {
        >
        > return false;
        > }
        >
        > The problem is that the character '¦' is testing as equal to '?'. This
        > character is Latin 1 A6.
        >
        > if ("?"=="¦") { alert("Holy Smoke!"); }
        >
        > It seems to only happen on IE6 (I've tried 6.0.2800.1106).
        > Anyone got any thoughts?
        >
        > Thanks
        > Andrew Cowper[/color]


        I can't help much, but, yes, I've seen this frequently in cases where
        wide to narrow character conversion was involved.

        In my quick test (also IE6),

        <meta http-equiv='content-type' content='text/html;charset=UT F-8'>
        <!-- meta http-equiv='content-type'
        content='text/html;charset=IS O-8859-1' -->
        <script type='text/javascript'>
        function test(){
        var b = "?"=="";
        alert('b: ' + b);
        }
        </script>

        <a href='#a1' name='a1' id='a1' onclick='test() ; return
        false;'>test</a>

        displays 'true' with UTF-8 but false with ISO-8859-1.

        I suppose it's a question of how the == operator code in a given
        browser compares a lower ASCII char to a wide char (not sure how many
        bytes UTF-8 needs for '¦'). I suppose a conversion of the wide char to
        a question mark might be intended to convey 'dunno what to make of
        this'.

        Not an expert. FWIW.

        Comment

        • Andrew Cowper

          #5
          Re: IE 6 Question Mark Wierdness

          gdsafford@hotma il.com (Greg) writes:
          [color=blue]
          > Andrew Cowper <junk.mail@bloa t.plus.com> wrote in
          > message news:<87fziy81r v.fsf@bloat.plu s.com>...[color=green]
          >> Anyone come across anything like this before? This is some javascript
          >> validation of user input.
          >>
          >> if ("?"=="¦") { alert("Holy Smoke!"); }
          >>[/color][/color]
          [color=blue]
          > displays 'true' with UTF-8 but false with ISO-8859-1.
          >[/color]

          Yes, we are serving our pages as UTF-8 so this fits. I think I'm just
          going to forget about testing for that character. Thanks Greg (and
          others) for your help...

          Andrew Cowper

          --
          Pick a different user name to email me.

          Comment

          Working...