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

オープン
#9,278 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript
領域
database

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
JavaScript
スター
17.6k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/pouchdb のほかの issue

apache/pouchdb の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。