From 7318592b16ec11a6dfa555a9f28017f83562ba7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 Oct 2016 18:27:43 +0200 Subject: [PATCH] B #4780: Fix label filter for labels with parenthesis --- src/sunstone/public/app/utils/labels/utils.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sunstone/public/app/utils/labels/utils.js b/src/sunstone/public/app/utils/labels/utils.js index 5246334043..f4e51cf5d2 100644 --- a/src/sunstone/public/app/utils/labels/utils.js +++ b/src/sunstone/public/app/utils/labels/utils.js @@ -360,10 +360,14 @@ define(function(require) { function _setLabelsFilter(dataTable, labelsColumn, label) { - var regExp = '^' + label + '$|'+ - ',' + label + '$|'+ - '^' + label + ',|'+ - ',' + label + ',' + // Make the label safe, it may contain regexp special characters. Source: + // https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions + var escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + + var regExp = '^' + escapedLabel + '$|'+ + ',' + escapedLabel + '$|'+ + '^' + escapedLabel + ',|'+ + ',' + escapedLabel + ',' dataTable.data("sunstone-label-filter", label); dataTable.fnFilter(regExp, labelsColumn, true, false);