Skip to main content

Bug Tracker

Side navigation

#3380 closed bug (fixed)

Opened September 19, 2008 01:33AM UTC

Closed February 07, 2009 03:32AM UTC

.hasClass(".name") silently dies

Reported by: dmethvin Owned by: flesler
Priority: major Milestone: 1.3
Component: selector Version: 1.2.6
Keywords: Cc: dmethvin, flesler
Blocked by: Blocking:

If you erroneously use $().hasClass() with a leading dot on the class name, jQuery silently stops executing code in FF3.

The actual problem seems to be in jQuery.filter, which matches the leading ".." in the selector it's given and then tries to look that up in jQuery.expr and gets undefined, but still tries to call it as a function.

This clearly is a user input error case so I wouldn't say the actual return value is critical, but the fact that jQuery dies in an unusual way makes debugging hard.

Attachments (2)
  • bad-filter-throw[5845].diff (0.4 KB) - added by flesler September 19, 2008 11:22PM UTC.
  • t.htm (0.4 KB) - added by dmethvin September 19, 2008 01:33AM UTC.

    Repro case for .hasClass(".name") bug

Change History (5)

Changed September 19, 2008 03:35PM UTC by flesler comment:1

cc: → dmethvin, flesler
need: ReviewPatch
owner: → flesler
status: newassigned

Changed September 19, 2008 04:21PM UTC by dmethvin comment:2

It occurred to me this morning that an easy fix for hasClass would be:

return "." + selector.replace(/^\\./,"") )

That has the nice effect of doing what the user really meant, too.

Changed September 19, 2008 06:21PM UTC by flesler comment:3

No, that's just a custom hack for this situation, not a fix.

Passing .foo to hasClass is with no doubt an error from the developer and we won't be patching things like that.

What I am considering is throwing an error inside the selector engine when an unrecognized filter is found.

Changed September 19, 2008 11:25PM UTC by flesler comment:4

This patch throws an error at least on these cases:


If you add a space between the tag and the filter it won't throw because that gets handled by find() and not by filter().

Changed February 07, 2009 03:32AM UTC by dmethvin comment:5

resolution: → fixed
status: assignedclosed

Confirmed this is fixed in jQuery 1.3.