Skip to main content

Bug Tracker

Side navigation

#7281 closed bug (invalid)

Opened October 22, 2010 05:44AM UTC

Closed July 03, 2012 02:20AM UTC

Sizzle Extension API is broken

Reported by: Ben Lambert <ben.nagoya@gmail.com> Owned by: timmywil
Priority: low Milestone: 1.8
Component: selector Version: 1.4.3
Keywords: sizzle extension api Cc:
Blocked by: Blocking:
Description

Currently new selectors cannot be added via the extension API documented in the Sizzle wiki: http://github.com/jeresig/sizzle/wiki

The issue is the

leftMatch
object-literal, which is filled by the follow code at initialization time:

for ( var type in Expr.match ) {
  Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\\[]*\\])(?![^\\(]*\\))/.source) );
  Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\\r|\\n)*?)/.source + Expr.match[ type ].source.replace(/\\\\(\\d+)/g, fescape) );
}

We need this code to be publicly exposed so that we can run it after adding new selectors via the extension API.

I've hacked around this by creating a new method (using Sizzle via jQuery):

Expr = $.expr;
Expr.process = function(type) {
  Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\\[]*\\])(?![^\\(]*\\))/.source );
  Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\\r|\\n)*?)/.source + Expr.match[ type ].source.replace(/\\\\(\\d+)/g, function(all, num){
    return "\\\\" + (num - 0 + 1);
  }));
};

which I use like this:

$.expr.match['WIDGET'] = /@((?:[\\w\\u00c0-\\uFFFF\\-]|\\\\.)+)/;

$.expr.preFilter.WIDGET = function(match) {
  return match[1].replace(/\\\\/g, "");
};

$.expr.filter.WIDGET = function(elem, match) {
  return elem.getAttribute('data-widget') === match;
};

$.expr.process('WIDGET');

Sizzle needs to expose the code that fills the leftMatch object via a function that works something like the one I've shown here.

Attachments (0)
Change History (8)

Changed October 23, 2010 08:11AM UTC by snover comment:1

owner: → Ben Lambert <ben.nagoya@gmail.com>
status: newpending

Is this broken in versions prior to 1.4.3?

Changed October 29, 2010 07:50AM UTC by Ben Lambert <ben.nagoya@gmail.com> comment:2

status: pendingnew

I'm not sure, I've not looked into the Sizzle source code before 1.4.3.

Presumably it was working at some point, like when the Sizzle API docs were written.

Changed October 29, 2010 02:28PM UTC by rwaldron comment:3

component: unfiledselector
keywords: → sizzle extension api
priority: undecidedlow
status: newopen

Changed March 31, 2011 01:57AM UTC by danheberden comment:4

milestone: → 1.next

Changed July 11, 2011 05:44PM UTC by john comment:5

owner: Ben Lambert <ben.nagoya@gmail.com>john
status: openassigned

Changed July 12, 2011 04:36PM UTC by john comment:6

Confirmed in bug triage.

Changed June 19, 2012 06:06AM UTC by timmywil comment:7

owner: johntimmywil

Changed July 03, 2012 02:20AM UTC by timmywil comment:8

milestone: 1.next1.8
resolution: → invalid
status: assignedclosed

No longer applies