Weird Safari JavaScript Error: When is a "<" not a "<"?

|

When it’s a “><”, of course!

Here’s the text of the original function in a standard html file. It’s properly enclosed in tags, and other parts of the script work, so don’t get your panties in a wad.

      function getArgs() {

      var args = new Object();
      var query = location.search.substring(1);
      var pairs = query.split("&");
      for(var i = 0; i < pairs.length; i++)
      {
      var pos = pairs[i].indexOf('=');
      if(pos == -1) continue;
      var argname = pairs[i].substring(0,pos)
      var value = pairs[i].substring(pos+1)
      args[argname] = unescape(value)
      }

      return args;
      }

This code is part of a custom app that my company uses, so I won’t publish the whole thing. (It’s available upon request—let me know and they’ll send it to you.) But suffice it to say that this code can be pretty easily found on the web, too. Just Google “getargs() javascript” and you can find numerous sources for it.

As best I can tell, Safari refuses to execute this code, instead returning a null value or something to the caller. When I look into the Web Inspector window to see what’s going on (because I’m curious like that), this is what I see:

Odd GTLT Comparator.jpg

Look at line 121 carefully. That’s an odd comparator, isn’t it?

I saved the original source of that page and put it onto my machine, which has only the proper “<” comparator in it, and verified that the Web Inspector window does indeed show me the odd “><” comparator, highlighted appropriately as if it were comparing i to < pairs.length.

I sent off a bug report to Apple using Safari’s feedback. But I’m not holding my breath.

Recent Comments