Skip to content

Commit

Permalink
fix para casos de case insensitive con arreglos
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Carlos Muñoz committed Oct 19, 2022
1 parent a397be4 commit 9cc28c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ module.exports = function(schema, options) {

// Wrap with case-insensitivity
if (get(path, "options.uniqueCaseInsensitive") || indexOptions.uniqueCaseInsensitive) {
// Escape RegExp chars
pathValue = pathValue.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
pathValue = new RegExp("^" + pathValue + "$", "i");
//no escapar si es un arreglo
if(!Array.isArray(pathValue)){
// Escape RegExp chars
pathValue = pathValue.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
pathValue = new RegExp("^" + pathValue + "$", "i");
}
}

conditions[name] = pathValue;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongoose-unique-validator",
"version": "2.1.2",
"version": "2.1.3",
"description": "mongoose-unique-validator is a plugin which adds pre-save validation for unique fields within a Mongoose schema.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 9cc28c4

Please sign in to comment.