From 9c78c06643eec8b1b39521e1d8b87c6e385d742f Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Sat, 30 Nov 2013 23:39:33 -0600 Subject: [PATCH] Make *Filter.matches case insensitive for attrs --- lib/filters/approx_filter.js | 7 ++++--- lib/filters/equality_filter.js | 5 +++-- lib/filters/ext_filter.js | 6 ++++-- lib/filters/ge_filter.js | 6 ++++-- lib/filters/le_filter.js | 6 ++++-- lib/filters/presence_filter.js | 2 +- lib/filters/substr_filter.js | 6 ++++-- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/filters/approx_filter.js b/lib/filters/approx_filter.js index 14b5aac..ebc081f 100644 --- a/lib/filters/approx_filter.js +++ b/lib/filters/approx_filter.js @@ -50,12 +50,13 @@ ApproximateFilter.prototype.matches = function (target) { throw new TypeError('target (object) required'); var matches = false; - if (target.hasOwnProperty(this.attribute)) { - var tv = target[this.attribute]; + var tv = Filter.get_attr_caseless(target, this.attribute); + + if (tv !== null) { if (Array.isArray(tv)) { matches = (tv.indexOf(this.value) != -1); } else { - matches = (this.value === target[this.attribute]); + matches = (this.value === tv); } } diff --git a/lib/filters/equality_filter.js b/lib/filters/equality_filter.js index 1ff1d8f..fc40d95 100644 --- a/lib/filters/equality_filter.js +++ b/lib/filters/equality_filter.js @@ -50,8 +50,9 @@ EqualityFilter.prototype.matches = function (target) { throw new TypeError('target (object) required'); var self = this; + var tv = Filter.get_attr_caseless(target, this.attribute); - if (target.hasOwnProperty(this.attribute)) { + if (tv !== null) { var value = this.value; return Filter.multi_test( function (v) { @@ -59,7 +60,7 @@ EqualityFilter.prototype.matches = function (target) { v = v.toLowerCase(); return value === v; }, - target[this.attribute]); + tv); } return false; diff --git a/lib/filters/ext_filter.js b/lib/filters/ext_filter.js index fd58101..59ebf62 100644 --- a/lib/filters/ext_filter.js +++ b/lib/filters/ext_filter.js @@ -94,7 +94,9 @@ ExtensibleFilter.prototype.matches = function (target) { return false; var self = this; - if (this.matchType && target.hasOwnProperty(this.matchType)) { + var tv = Filter.get_attr_caseless(target, this.matchType); + + if (this.matchType && tv !== null) { if (self.rule === '2.5.13.4' || self.rule === 'caseIgnoreSubstringsMatch') { var f = { @@ -120,7 +122,7 @@ ExtensibleFilter.prototype.matches = function (target) { } return self.value === v; - }, target[this.matchType]); + }, tv); } return false; diff --git a/lib/filters/ge_filter.js b/lib/filters/ge_filter.js index 98f099d..26c62a9 100644 --- a/lib/filters/ge_filter.js +++ b/lib/filters/ge_filter.js @@ -50,11 +50,13 @@ GreaterThanEqualsFilter.prototype.matches = function (target) { if (typeof (target) !== 'object') throw new TypeError('target (object) required'); - if (target.hasOwnProperty(this.attribute)) { + var tv = Filter.get_attr_caseless(target, this.attribute); + + if (tv !== null) { var value = this.value; return Filter.multi_test( function (v) { return value <= v; }, - target[this.attribute]); + tv); } return false; diff --git a/lib/filters/le_filter.js b/lib/filters/le_filter.js index a2f5520..5b63de8 100644 --- a/lib/filters/le_filter.js +++ b/lib/filters/le_filter.js @@ -50,11 +50,13 @@ LessThanEqualsFilter.prototype.matches = function (target) { if (typeof (target) !== 'object') throw new TypeError('target (object) required'); - if (target.hasOwnProperty(this.attribute)) { + var tv = Filter.get_attr_caseless(target, this.attribute); + + if (tv !== null) { var value = this.value; return Filter.multi_test( function (v) { return value >= v; }, - target[this.attribute]); + tv); } return false; diff --git a/lib/filters/presence_filter.js b/lib/filters/presence_filter.js index f37ec36..8070ec0 100644 --- a/lib/filters/presence_filter.js +++ b/lib/filters/presence_filter.js @@ -44,7 +44,7 @@ PresenceFilter.prototype.matches = function (target) { if (typeof (target) !== 'object') throw new TypeError('target (object) required'); - return target.hasOwnProperty(this.attribute); + return (Filter.get_attr_caseless(target, this.attribute) !== null); }; diff --git a/lib/filters/substr_filter.js b/lib/filters/substr_filter.js index 07a23da..9c3a0d8 100644 --- a/lib/filters/substr_filter.js +++ b/lib/filters/substr_filter.js @@ -75,7 +75,9 @@ SubstringFilter.prototype.matches = function (target) { if (typeof (target) !== 'object') throw new TypeError('target (object) required'); - if (target.hasOwnProperty(this.attribute)) { + var tv = Filter.get_attr_caseless(target, this.attribute); + + if (tv !== null) { var re = ''; if (this.initial) re += '^' + escapeRegExp(this.initial) + '.*'; @@ -95,7 +97,7 @@ SubstringFilter.prototype.matches = function (target) { v = v.toLowerCase(); return matcher.test(v); }, - target[this.attribute]); + tv); } return false;