From a5148c9e6376c04f4a95b6a150c52041731f54b0 Mon Sep 17 00:00:00 2001 From: Chris Tanner Date: Thu, 24 May 2018 15:49:21 -0700 Subject: [PATCH] Escape regex characters before parsing them --- demo/index.htm | 2 +- dist/jquery.bootgrid.css | 4 ++-- dist/jquery.bootgrid.fa.js | 4 ++-- dist/jquery.bootgrid.js | 17 +++++++++++------ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/demo/index.htm b/demo/index.htm index ed4dd00..a35686e 100644 --- a/demo/index.htm +++ b/demo/index.htm @@ -274,7 +274,7 @@ 20 01 - nulla.magna.malesuada@musProin.edu + [nulla.magna.malesuada@musProin.edu 30.01.17 Ac Urna Corp. 2 diff --git a/dist/jquery.bootgrid.css b/dist/jquery.bootgrid.css index 3164924..3a95473 100644 --- a/dist/jquery.bootgrid.css +++ b/dist/jquery.bootgrid.css @@ -1,6 +1,6 @@ /*! - * jQuery Bootgrid v1.4.2 - 08/02/2017 - * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) + * jQuery Bootgrid v1.4.2 - 05/24/2018 + * Copyright (c) 2014-2018 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ .bootgrid-header, diff --git a/dist/jquery.bootgrid.fa.js b/dist/jquery.bootgrid.fa.js index 928c54e..45e152d 100644 --- a/dist/jquery.bootgrid.fa.js +++ b/dist/jquery.bootgrid.fa.js @@ -1,6 +1,6 @@ /*! - * jQuery Bootgrid v1.4.2 - 08/02/2017 - * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) + * jQuery Bootgrid v1.4.2 - 05/24/2018 + * Copyright (c) 2014-2018 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ ;(function ($, window, undefined) diff --git a/dist/jquery.bootgrid.js b/dist/jquery.bootgrid.js index a6dcb24..0b815c5 100644 --- a/dist/jquery.bootgrid.js +++ b/dist/jquery.bootgrid.js @@ -1,6 +1,6 @@ /*! - * jQuery Bootgrid v1.4.2 - 08/02/2017 - * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) + * jQuery Bootgrid v1.4.2 - 05/24/2018 + * Copyright (c) 2014-2018 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ ;(function ($, window, undefined) @@ -87,11 +87,15 @@ function highlightAppendedRows(rows) { } } +function escapeRegExp(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); +} + // Replaces all occurrences of the word in the given html // Original source: http://stackoverflow.com/questions/8503121/replace-words-in-a-string-but-ignore-html function highlightResults(html) { var that = this, - word = that.searchPhrase, + word = escapeRegExp(that.searchPhrase), tpl = this.options.templates, css = this.options.css, container = document.createElement("div"), @@ -189,6 +193,8 @@ response = { } */ + + function loadData() { var that = this; @@ -196,9 +202,8 @@ function loadData() { showLoading.call(this); function containsPhrase(row) { - var column, - searchPattern = new RegExp(that.searchPhrase, (that.options.caseSensitive) ? "g" : "gi"); - + var column; + var searchPattern = new RegExp(escapeRegExp(that.searchPhrase), (that.options.caseSensitive) ? "g" : "gi"); for (var i = 0; i < that.columns.length; i++) { column = that.columns[i]; if (column.searchable && (column.visible || that.options.searchSettings.includeHidden) &&