Bug Tracker

Opened 10 years ago

Closed 9 years ago

#4817 closed bug (fixed)

hasClass expands selector metacharacters

Reported by: sixtease Owned by:
Priority: low Milestone: 1.4.2
Component: attributes Version: 1.3.2
Keywords: selector, hasClass, class, metacharacter, needsreview Cc:
Blocked by: Blocking:

Description

hasClass method doesn't recognize classes with dots and other metacharacters. They must be escaped.

<div id="dotclass" class="has.dot"></div>
<script>
if ( $('#dotclass').hasClass('has.dot') ) alert('works');
else alert('fails');
if ( $('#dotclass').hasClass('has\\.dot') ) alert('works with \\\\');
</script>

Attachments (2)

jquery-hasClass.diff (560 bytes) - added by sixtease 10 years ago.
patch
hasClass-test.html (757 bytes) - added by sixtease 10 years ago.
test

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by sixtease

Attachment: jquery-hasClass.diff added

patch

Changed 10 years ago by sixtease

Attachment: hasClass-test.html added

test

comment:1 Changed 9 years ago by addyosmani

Keywords: needsreview added

Your test case works fine using both the standard '.' form and a single forward-slash. Given that a well-named class shouldn't contain multiple meta-characters (eg.

\) in the first place, I want to flag this as an edge-case that probably will not be experienced by a large number of users. Leaving it open for now.

comment:2 Changed 9 years ago by jitter

Component: coreattributes
Milestone: 1.41.4.2
Priority: minorlow
Resolution: fixed
Status: newclosed

test case was fixed with 1.4.2.

If the bug still exists for you, feel free to reopen with a test case.

Note: See TracTickets for help on using tickets.