This project is archived and is in readonly mode.

#1186 ✓duplicate
Jacob

getElements startsWith not accepting multiple square brackets

Reported by Jacob | March 2nd, 2011 @ 02:38 AM | in 1.4.0 (closed)

Using CSS selectors in getElements and a pseudo selector returns elements that it should if there are more than one pair of brackets.

i.e.
With an checkbox and selector like so:

<input type="checkbox" name="test[][]"/>
document.getElements('input[name^=test[][]]:checked')

The input box is returned regardless of if its checked or not.
Not using the startsWith operator is works fine, and using it on a checkbox with only 1 set of square brackets works fine.

document.getElements('input[name=test[][]]:checked')

or

<input type="checkbox" name="test[]"/>
document.getElements('input[name^=test[]]:checked')

This bug was not occurring in 1.2.5, but is in 1.3.1.
See http://jsfiddle.net/PqXdX

I solved the problem by using quotes, but it seemed like unexpected behaviour.

Comments and changes to this ticket

  • Fábio M. Costa

    Fábio M. Costa March 2nd, 2011 @ 03:30 AM

    • Tag set to slick selector
    • Milestone set to 1.4.0
    • Assigned user set to “Fábio M. Costa”
    • Milestone order changed from “891” to “0”

    I'm gonna take a look at this, but in cases like this, you should always try to use quotes, because otherwise querySelectorAll, the native browser method for CSS selection, will throw an error, and you won't be able to have them optimized (by now).

    I'm on chrome right now and "input[name^=test[]]:checked" throws a syntax error while "input[name^='test[]']:checked" doesn't.

    Others examples that throw error on the native function (they all work fine while using Slick):

    • a[href^=#some]
    • input[name^=some.name]
    • input[name^=some:name]

    You can imagine why it throws errors and why they should be quoted.

    I'm thinking about automatically quoting attribute selector values. thoughts?

    Thanks for the report :)

  • Christoph Pojer

    Christoph Pojer March 2nd, 2011 @ 07:54 PM

    @Fabio: I think this is a wontfix. Automatically quoting might have undesired side effects. If you use square brackets, always use quotes, that's how its gotta be.

  • Fábio M. Costa

    Fábio M. Costa March 2nd, 2011 @ 11:19 PM

    • State changed from “new” to “open”

    I was thinking cause before the native match function call we do a normalization to include the quotes, because the match function on attribute selectors were giving too much syntax errors on unquoted values. So quoting before QSA would be consistent with the behavior we got on the match function.

    I'll keep it open, one time we will see if it's safe or not to do it.

  • Christoph Pojer

    Christoph Pojer August 13th, 2011 @ 12:58 AM

    • State changed from “open” to “duplicate”

    Reposted on the slick issue tracker: https://github.com/mootools/slick/issues/47

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages