Skip to content

Commit

Permalink
Ensure Enumerable#grep can handle strings with RegExp metacharacters. [
Browse files Browse the repository at this point in the history
…#257 state:resolved]
  • Loading branch information
savetheclocktower committed Dec 20, 2008
1 parent e9e8c7f commit 9f5c40c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lang/enumerable.js
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions test/unit/enumerable_test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 9f5c40c

Please sign in to comment.