IE 6 Question Mark Wierdness

A

Andrew Cowper

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
 
A

asdf asdf

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;
 
D

Douglas Crockford

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
 
G

Greg

Andrew Cowper said:
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.
 
A

Andrew Cowper

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top