From 96d3de1858ff91c9726e81c344cd5a4ea2cce4b7 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 3 Oct 2012 16:03:29 -0400 Subject: [PATCH] Fix jQuery #12643: don't tokenize trailing commas --- sizzle.js | 3 ++- test/unit/selector.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sizzle.js b/sizzle.js index 0f4df28f..f7a23bfc 100644 --- a/sizzle.js +++ b/sizzle.js @@ -1029,7 +1029,8 @@ function tokenize( selector, parseOnly ) { // Comma and first run if ( !matched || (match = rcomma.exec( soFar )) ) { if ( match ) { - soFar = soFar.slice( match[0].length ); + // Don't consume trailing commas as valid + soFar = soFar.slice( match[0].length ) || soFar; } groups.push( tokens = [] ); } diff --git a/test/unit/selector.js b/test/unit/selector.js index aa6ebd44..73d78471 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -164,7 +164,7 @@ test("XML Document Selectors", function() { }); test("broken", function() { - expect( 21 ); + expect( 22 ); function broken( name, selector ) { raises(function() { @@ -183,6 +183,7 @@ test("broken", function() { broken( "Broken Selector", "{}" ); broken( "Broken Selector", "," ); broken( "Broken Selector", ",a" ); + broken( "Broken Selector", "a," ); // Hangs on IE 9 if regular expression is inefficient broken( "Broken Selector", "[id=012345678901234567890123456789"); broken( "Doesn't exist", ":visble" );