Bug Tracker

Opened 10 years ago

Closed 9 years ago

#6328 closed bug (worksforme)

Attribute selector with escaped character doesn't work when used with a context

Reported by: slaren Owned by:
Priority: undecided Milestone:
Component: selector Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Description

When filtering by attribute no results are returned if a "[" escaped character is used in conjunction with a context. No errors are reported by jQuery either.

This can be reproduced with the following code (tested with Firefox 3.6):

<html>
<head>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
$(function()
{
    var ctx = $("#mydiv");
    
    // outputs "1: test[0]"
    $("select[name^=test]", ctx).each(function() { console.log("1: " + $(this).attr("name")) });
    
    // no output
    $("select[name^=test\\[]", ctx).each(function() { console.log("2: " + $(this).attr("name")) });
    
    // outputs "3: test[0]"
    $("select[name^=test\\[]").each(function() { console.log("3: " + $(this).attr("name")) });
});    
</script>
</head>
<body>
    <div id="mydiv">
        <select name="test[0]"></select>
    </div>
</body>
</html>

Change History (2)

comment:1 Changed 10 years ago by shoty

When using a selector and specify the context, or directly using .find, the selector indeed doesn't work with escaped
[
]
Doesn't work:

jQuery('input[name="f\\[first_name\\]"]','#main_form');
jQuery('#main_form').find('input[name="f\\[first_name\\]"]');

The following works:

jQuery('input[name="f[first_name]"]','#main_form');
jQuery('#main_form').find('input[name="f[first_name]"]');

This one works also (but the context is not used and matches from whole document)

jQuery('input[name="f\\[first_name\\]"]')

My question is if this is a bug in the current version and will be updated or this is how it should work?

comment:2 Changed 9 years ago by dmethvin

Priority: undecided
Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.