Bug Tracker

Opened 9 years ago

Closed 7 years ago

#7281 closed bug (invalid)

Sizzle Extension API is broken

Reported by: Ben Lambert <ben.nagoya@…> 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.

Change History (8)

comment:1 Changed 9 years ago by snover

Owner: set to Ben Lambert <ben.nagoya@…>
Status: newpending

Is this broken in versions prior to 1.4.3?

comment:2 Changed 9 years ago by Ben Lambert <ben.nagoya@…>

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.

comment:3 Changed 9 years ago by Rick Waldron

Component: unfiledselector
Keywords: sizzle extension api added
Priority: undecidedlow
Status: newopen

comment:4 Changed 9 years ago by danheberden

Milestone: 1.next

comment:5 Changed 8 years ago by john

Owner: changed from Ben Lambert <ben.nagoya@…> to john
Status: openassigned

comment:6 Changed 8 years ago by john

Confirmed in bug triage.

comment:7 Changed 7 years ago by timmywil

Owner: changed from john to timmywil

comment:8 Changed 7 years ago by timmywil

Milestone: 1.next1.8
Resolution: invalid
Status: assignedclosed

No longer applies

Note: See TracTickets for help on using tickets.