Ensure Enumerable#grep can handle strings with RegExp metacharacters. [#257 state:resolved]

This commit is contained in:
Andrew Dupont 2008-12-19 18:50:08 -06:00
parent e9e8c7fbe5
commit 9f5c40c744
3 changed files with 11 additions and 1 deletions

View File

@ -1,3 +1,5 @@
* Ensure Enumerable#grep can handle strings with RegExp metacharacters. (Marton Kiss-Albert, kangax)
* Switch to the "doScroll approach" for the dom:loaded custom event. (javier, Diego Perini, Nick Stakenburg, Andrew Dupont)
* Optimize document.viewport.get(Dimensions|Width|Height). (Nick Stakenburg, Andrew Dupont)

View File

@ -75,7 +75,7 @@ var Enumerable = (function() {
var results = [];
if (Object.isString(filter))
filter = new RegExp(filter);
filter = new RegExp(RegExp.escape(filter));
this.each(function(value, index) {
if (filter.match(value))

View File

@ -136,6 +136,14 @@ new Test.Unit.Runner({
this.assertEnumEqual($('grepHeader', 'grepCell'),
$('grepTable', 'grepTBody', 'grepRow', 'grepHeader', 'grepCell').grep(new Selector('.cell')));
// troublesome characters
this.assertEnumEqual(['?a', 'c?'], ['?a','b','c?'].grep('?'));
this.assertEnumEqual(['*a', 'c*'], ['*a','b','c*'].grep('*'));
this.assertEnumEqual(['+a', 'c+'], ['+a','b','c+'].grep('+'));
this.assertEnumEqual(['{1}a', 'c{1}'], ['{1}a','b','c{1}'].grep('{1}'));
this.assertEnumEqual(['(a', 'c('], ['(a','b','c('].grep('('));
this.assertEnumEqual(['|a', 'c|'], ['|a','b','c|'].grep('|'));
},
testInclude: function() {