Bug Tracker

Ticket #8453 (closed bug: invalid)

Opened 4 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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/]'))

Change History

comment:1 Changed 4 years ago by rwaldron

  • Owner set to koenpeters
  • Status changed from new to pending
  • Component changed from unfiled to selector

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.

comment:2 Changed 4 years ago by anonymous

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.

comment:3 Changed 4 years ago by addyosmani

  • Priority changed from undecided to low
  • Status changed from pending to closed
  • Resolution set to invalid

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.

comment:4 Changed 4 years ago by anonymous

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.

Note: See TracTickets for help on using tickets.