There is a beginning of time bug in MongoDB's integration with the PCRE library that causes the string data stored in a document to be truncated at the first NUL byte when attempting to do pattern matching on it. This line is the cause of the issue because we will end up using the StringPiece(const char* str) constructor, which calls strlen(), and thus causes the pattern matching on the string data to stop at the first NUL byte.
We should instead use the StringPiece(const char* offset, int len) constructor and pass e.valuestrsize() - 1 as the length of the string data.
Additionally, it is worth noting that PCRE patterns cannot contain embedded NUL bytes. Instead, they need to be escaped as
"\\000", "\\x00",
etc. See my comment below for more details.
Original description
In version 2.4.7 and 3.0.3:
The value contains an special characters '\u0000' (\x00, \0),use prefix search like "^a\u0000", but get an item which do not have the prefix "a\u0000" like "a".
In version 1.8.3:
when search with "^a", the item "a\u0000" is not in result set.
- is duplicated by
-
SERVER-25030 end-of-string anchor matches null character in regex
- Closed
-
SERVER-3720 regex match null character
- Closed