Skip to content

Passing a RegExp object to $regex inside $elemMatch causes a crash #9278

Description

@stevecassidy

Issue

I came across a quirk/bug in pouchdb yesterday, I'm not sure whether to report it.   It relates to the use of $regex inside $elemMatch in a find query.  We wanted to have a case insensitive regex and so passed in a Javascript RegExp object asa the pattern.   This worked as long as the $elemMatch branch did not trigger - for plain values the expression matches ok.   If the value is an array of objects, we get a crash inside pouchdb.

So this could just be that we're over-reaching in our use of $regex by sending a RegExp object. There is no documentation about what kind of value we can pass other than a pointer to the CouchDB docs which then points to the Erlang reference and PCRE.  Based on PCRE I could use (?i) to make the pattern case insensitive but this is not accepted by pouchdb - as far as I can see it just passes the pattern internally to RegExp.

The easiest route to being able to support case-insensitive regex would be to fix this regression and document the use of RegExp, however this wouldn't work for the http backend since CouchDB expects PCRE expressions. The alternate would be to support PCRE modifiers in the local backend. Some mention of compatibility in the documentation would also be useful.

Info

  • Environment: NodeJS and browser using in-memory and indexedDB backends
  • Platform: Node and Chrome tested
  • Adapter: memory, indexeddb
  • Server: None

Reproduce

The attached script shows a reproduction. It adds documents including one containing an array of one object, then runs the query using both string and RegExp patterns. Comment out the first document in the bulkDocs call to avoid the crash.

repro-pouchdb-elemmatch.js

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions