question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filters match on attribute values only case-sensitively

See original GitHub issue

Many LDAP attributes (eg. cn, givenName) are defined as defaulting to case-insensitive when it comes to applying filters. However:

> ldap = require('ldapjs')
> filter = ldap.parseFilter('(cn=*bob*)')
> filter.matches({cn: 'bob'})
true
> filter.matches({cn: 'Bob'})
false

My suggestion:

  • Make all filters case-__in__sensitive by default, since I suspect that is the most common use-case (it certainly is for me),
  • Add an argument to filter.matches(...) (or when creating a Filter object) which allows us to indicate which attributes are case-sensitive.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alansouzaticommented, Jun 8, 2016

this is what I had to do, I’m sure that has to be an easier way to accomplish this:

import ldap from 'ldapjs';
import helpers from 'ldap-filter/lib/helpers';

function escapeRegExp(str) {
  /* JSSTYLED */
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}

ldap.SubstringFilter.prototype.matches = function (target, strictAttrCase) {
  var tv = helpers.getAttrValue(target, this.attribute, strictAttrCase);
  if (tv !== undefined && tv !== null) {
    var re = '';

    if (this.initial)
      re += '^' + escapeRegExp(this.initial) + '.*';
    this.any.forEach(function (s) {
      re += escapeRegExp(s) + '.*';
    });
    if (this.final)
      re += escapeRegExp(this.final) + '$';

    var matcher = new RegExp(re, 'i');
    return helpers.testValues(function (v) {
      return matcher.test(v);
    }, tv);
  }

  return false;
};

The only thing I had to change was var matcher = new RegExp(re); to var matcher = new RegExp(re, 'i');

0reactions
alansouzaticommented, Jun 8, 2016

hi @pfmooney, can you provide directions on how to override the filter match methods?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filters match on attribute values only case-sensitively #156
Many LDAP attributes (eg. cn, givenName) are defined as defaulting to case-insensitive when it comes to applying filters.
Read more >
Enhanced Subscriber Feature Data Filter Operators for ...
Search strings are not case-sensitive. Subscribers with an attribute definition that matches one of the values you define in a comma delimited string...
Read more >
14.3. LDAP Search Filters Red Hat Directory Server 11
Compares the given search value to a string in an attribute value. This matching rule is case-insensitive. OID: 2.5.13.32. Compatible syntaxes: Directory String....
Read more >
LDAP Filters
An equality filter is used to determine whether an entry contains a specified attribute value. If an entry includes the specified value, regardless...
Read more >
Entity Search API returns no results when filter uses 'contains ...
The "equals" filter description is - ( property, value ). This means it filters all the conditions with the exact match while ignoring...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found