Skip to main content

Bug Tracker

Side navigation

#8453 closed bug (invalid)

Opened March 06, 2011 04:31PM UTC

Closed March 09, 2011 04:00PM UTC

Last modified March 14, 2012 06:17PM UTC

In IE the is() function triggers a sizzle exception that is not handled correctly when used with a 'naked' attribute selector

Reported by: koenpeters Owned by: koenpeters
Priority: low Milestone: 1.next
Component: selector Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

Try the following code:

<html DOCTYPE="html">
<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
  <script>
    $(document).ready(function() {
      if ($('a').is('[href=http://www.isaac.nl/]')) {
        $('div').text('');
      } 
    });
  </script>
</head>
<body>
  <a href="http://www.isaac.nl/">link text</a>
  <div>If you see this message the error occured</div>
</body>
</html>

When you run this in anything except IE the text "If you see this message the error occured" will be removed. In IE however the following exception will be thrown:

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Sun, 6 Mar 2011 16:22:30 UTC


Message: Exception thrown and not caught
Line: 871
Char: 15
Code: 0
URI: http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js

When an 'a' is added it does not throw the exception and runs as expected:

is('a[href=http://www.isaac.nl/]'))
Attachments (0)
Change History (4)

Changed March 07, 2011 01:15AM UTC by rwaldron comment:1

component: unfiledselector
owner: → koenpeters
status: newpending

Attribute selectors should always have the value enclosed in quotes - while this may not fix your issue, it's important to make sure that your code examples are valid.

Changed March 09, 2011 02:26PM UTC by anonymous comment:2

Adding the extra quotes fixes the issue. However, the handling of the Sizzle error when we omit the quotes is a little strange. Below is the JQuery code that handles the Sizzle error (it is the line of code where IE says that an error has occurred):

Sizzle.error = function( msg ) {
	throw "Syntax error, unrecognized expression: " + msg;
};

The IE error message states: "Message: Exception thrown and not caught". I think the actual error ("Syntax error, unrecognized expression: " + msg;) should be visible in the error window. I'm not sure if this is a limitation in IE or a bug in JQuery.

Changed March 09, 2011 04:00PM UTC by addyosmani comment:3

priority: undecidedlow
resolution: → invalid
status: pendingclosed

Given that the issue in the original ticket was caused by a lack of including the extra quotes, as rwaldron has pointed out as being quite necessary for using attribute selectors in this manner, we'll be closing it. Please feel free to continue the discussion on this ticket if needed.

Changed March 15, 2011 07:59PM UTC by anonymous comment:4

Is jQuery ever considering handling invalid function calls with some form of error tracking (such as allowing for a user-defined error handler and calling it when bad values are sent, rather than crashing 100 lines into some complicated javascript file I don't understand)?

I love jQuery, just have a lot of pain tracking down certain errors.