From 9cc28c417eb9d42f79ba627a4f6f9dd442db11b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mu=C3=B1oz?= Date: Wed, 19 Oct 2022 11:34:05 -0300 Subject: [PATCH] fix para casos de case insensitive con arreglos --- index.js | 9 ++++++--- package.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6422be8..e6d39f1 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index 5a5b092..4ddcd38 100644 --- a/package.json +++ b/package.json @@ -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": {