#257 bug
Marton Kiss-Albert

Enumerable.grep() not supported fully string pattern

Reported by Marton Kiss-Albert | July 30th, 2008 @ 10:05 PM | in 1.6.1

Enumerable.grep() function not supprted fully string filter. (like gsub - bug 252)

	a=['bad smile :-)','bad smile :-)'];
	a.grep(':-)');

regexp error....

Patch:

  grep: function(filter, iterator, context) {
    iterator = iterator ? iterator.bind(context) : Prototype.K;
    var results = [];

    if (Object.isString(filter))
      // filter = new RegExp(filter); <-- OLD VERSION
      filter = new RegExp(RegExp.escape(filter)); // <-- PATCHED VERSION

    this.each(function(value, index) {
      if (filter.match(value))
        results.push(iterator(value, index));
    });
    return results;
  },

Comments and changes to this ticket

  • John-David Dalton

    John-David Dalton July 31st, 2008 @ 12:02 AM

    • → Milestone changed from “” to “1.6.1”
    • → State changed from “new” to “bug”
    • → Title changed from “grep not supported fully string pattern” to “Enumerable.grep() not supported fully string pattern”
    • → Assigned user changed from “” to “John-David Dalton”
  • Marton Kiss-Albert

    Marton Kiss-Albert July 31st, 2008 @ 07:37 AM

    • → Tag changed from “bug patched regexp string” to “patched regexp tested”

    OR:

    filter = RegExp.escape(filter);
    

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket