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

Aperta
#9,278 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
database

Direzione di ricerca

Start by running the attached repro-pouchdb-elemmatch.js in the Node.js environment and compare string and RegExp patterns inside $elemMatch. Trace the crash for arrays of objects in the memory and indexedDB backends; done means the reproduced query no longer crashes and the supported regex behavior or compatibility limitation is documented.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
JavaScript
Stelle
17.6k
Fork
1.5k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/pouchdb

Tutte le issue di apache/pouchdb

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.