IE 6 Question Mark Wierdness

Discussion in 'Javascript' started by Andrew Cowper, Sep 15, 2003.

  1. 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.
     
    Andrew Cowper, Sep 15, 2003
    #1
    1. Advertising

  2. Andrew Cowper

    asdf asdf Guest

    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;
     
    asdf asdf, Sep 15, 2003
    #2
    1. Advertising

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


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

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

    http://www.JSON.org
     
    Douglas Crockford, Sep 15, 2003
    #3
  4. Andrew Cowper

    Greg Guest

    Andrew Cowper <> wrote in message news:<>...
    > 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



    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=UTF-8'>
    <!-- meta http-equiv='content-type'
    content='text/html;charset=ISO-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.
     
    Greg, Sep 15, 2003
    #4
  5. (Greg) writes:

    > Andrew Cowper <> wrote in
    > message news:<>...
    >> Anyone come across anything like this before? This is some javascript
    >> validation of user input.
    >>
    >> if ("?"=="¦") { alert("Holy Smoke!"); }
    >>


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


    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.
     
    Andrew Cowper, Sep 16, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Terry Olsen

    Datagrid Cell Spacing Wierdness

    Terry Olsen, Mar 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    583
    Terry Olsen
    Mar 29, 2005
  2. danthman

    Wierdness with "Imports" statement

    danthman, Dec 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,200
    danthman
    Dec 16, 2005
  3. Larry
    Replies:
    0
    Views:
    408
    Larry
    Feb 17, 2006
  4. VisionSet
    Replies:
    0
    Views:
    401
    VisionSet
    Aug 29, 2004
  5. Cirene
    Replies:
    5
    Views:
    614
    Cirene
    May 17, 2008
Loading...

Share This Page