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

Đang mở
#9,278 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript
Lĩnh vực
database

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
JavaScript
Star
17.6k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/pouchdb

Tất cả issue của apache/pouchdb

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.