Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Whitespace in (old) parseFilter causes Uncaught Error: missing paren #962

Closed
ernstki opened this issue Jan 10, 2024 · 0 comments
Closed

Comments

@ernstki
Copy link

ernstki commented Jan 10, 2024

I suppose this has probably been worked around in a current version, but I'm documenting it here for posterity, in case someone else runs into the same issue with another project that requires an earlier ldapjs / ldap-filter.

This works as expected:

> parseFilter = require(ldapjs).parseFilter;

> f = parseFilter('(&(objectclass=organizationalPerson)(|(memberOf=CN=group1,OU=foo,DC=org)(memberOf=CN=group2,OU=foo,DC=org)))');
AndFilter {
  filters: [
    EqualityFilter {
      attribute: 'objectclass',
      raw: <Buffer 6f 72 67 61 6e 69 7a 61 74 69 6f 6e 61 6c 50 65 72 73 6f 6e>
    },
    OrFilter { filters: [Array] }
  ]
}

However, add a space and you get Uncaught Error: missing paren:

> f = parseFilter('(&(objectclass=organizationalPerson)(|(memberOf=CN=group1,OU=foo,DC=org) (memberOf=CN=group2,OU=foo,DC=org)))');
Uncaught Error: missing paren
    at parseFilter (/usr/src/app/node_modules/ldap-filter/lib/index.js:198:13)
    at parseFilter (/usr/src/app/node_modules/ldap-filter/lib/index.js:213:13)
    at parseFilter (/usr/src/app/node_modules/ldap-filter/lib/index.js:204:13)
    at Object.parse (/usr/src/app/node_modules/ldap-filter/lib/index.js:252:18)
    at parseString (/usr/src/app/node_modules/ldapjs/lib/filters/index.js:179:27)

Note that the only tiny difference in the above, relative the previous one, is the single space between the two terms of the | expression. By comparison, ldapsearch accepts this expression, no issue.

The error message is better than nothing, I guess, but it's not technically correct either—the paren is there, it's just after a space that the parser didn't expect.

Workaround

Remove all spaces in between the terms of a & or | expression. I welcome corrections if I'm using the wrong terminology here, too, since this isn't stuff I work with every day.

Resolution

Closing, because I don't have the wherewithal to test with 3.x right now. Drop a comment if you're still affected by this problem with the current version(s) out there and wish to have the issue re-opened.

@ernstki ernstki closed this as completed Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant