Browse files

fix for .match()

  • Loading branch information...
1 parent 21eca01 commit e561ab62ca60f6311ada4b23485600409888aea3 @dvv dvv committed Nov 29, 2010
Showing with 4 additions and 3 deletions.
  1. +4 −3 lib/js-array.js
View
7 lib/js-array.js
@@ -345,14 +345,15 @@ function query(query, options, target){
if(jsOperator){
// item['foo.bar'] ==> (item && item.foo && item.foo.bar && ...)
var path = String(value.args[0]);
- var item = path ? path.split('.').map(function(x,i,a){return 'item.'+a.slice(0,i+1).join('.')}).join('&&') : 'item';
+ var item = path ? path.split('.').map(function(x,i,a){return 'item.'+a.slice(0,i+1).join('.')}).join('&&') : 'item';
+ item = '('+item+')';
if (jsOperator === '===' && value.args[1] instanceof RegExp){
// N.B. matching requires String
- item = 'String(item.' + value.args[0] + ')';
+ item = 'String('+item + '||"")';
jsOperator = '.match('+value.args[1]+')&&""===';
value.args[1] = '';
}
- return "(function(){var filtered = []; for(var i = 0, length = this.length; i < length; i++){var item = this[i];if((" + item + ')' + jsOperator + queryToJS(value.args[1]) + "){filtered.push(item);}} return filtered;})";
+ return "(function(){var filtered = []; for(var i = 0, length = this.length; i < length; i++){var item = this[i];if(" + item + jsOperator + queryToJS(value.args[1]) + "){filtered.push(item);}} return filtered;})";
}else{
return "(function(){return (operators['" + value.name + "']||exports.missingOperator('" + value.name + "')).call(this" +
(value && value.args && value.args.length > 0 ? (", " + value.args.map(queryToJS).join(",")) : "") +

0 comments on commit e561ab6

Please sign in to comment.