From 0be87fcebd690dd93a8fb79aa137131aa7a17538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Despont?= Date: Tue, 26 Nov 2024 17:19:11 +0100 Subject: [PATCH 1/3] Fix strictSearch --- src/bootstrap-table.js | 80 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/bootstrap-table.js b/src/bootstrap-table.js index f1c080f81..ff237bbb0 100644 --- a/src/bootstrap-table.js +++ b/src/bootstrap-table.js @@ -1117,50 +1117,50 @@ class BootstrapTable { if (typeof value === 'string' || typeof value === 'number') { if ( - this.options.strictSearch && `${value}`.toLowerCase() === searchText || - this.options.regexSearch && Utils.regexCompare(value, rawSearchText) + (this.options.strictSearch && `${value}`.toLowerCase() === searchText) || + (this.options.regexSearch && Utils.regexCompare(value, rawSearchText)) ) { return true - } - - const largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(-?\d+)?|(-?\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm - const matches = largerSmallerEqualsRegex.exec(this.searchText) - let comparisonCheck = false - - if (matches) { - const operator = matches[1] || `${matches[5]}l` - const comparisonValue = matches[2] || matches[3] - const int = parseInt(value, 10) - const comparisonInt = parseInt(comparisonValue, 10) - - switch (operator) { - case '>': - case ' comparisonInt - break - case '<': - case '>l': - comparisonCheck = int < comparisonInt - break - case '<=': - case '=<': - case '>=l': - case '=>l': - comparisonCheck = int <= comparisonInt - break - case '>=': - case '=>': - case '<=l': - case '== comparisonInt - break - default: - break + } else { + const largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(-?\d+)?|(-?\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm + const matches = largerSmallerEqualsRegex.exec(this.searchText) + let comparisonCheck = false + + if (matches) { + const operator = matches[1] || `${matches[5]}l` + const comparisonValue = matches[2] || matches[3] + const int = parseInt(value, 10) + const comparisonInt = parseInt(comparisonValue, 10) + + switch (operator) { + case '>': + case ' comparisonInt + break + case '<': + case '>l': + comparisonCheck = int < comparisonInt + break + case '<=': + case '=<': + case '>=l': + case '=>l': + comparisonCheck = int <= comparisonInt + break + case '>=': + case '=>': + case '<=l': + case '== comparisonInt + break + default: + break + } } - } - if (comparisonCheck || `${value}`.toLowerCase().includes(searchText)) { - return true + if (comparisonCheck || `${value}`.toLowerCase().includes(searchText)) { + return true + } } } } From 94e46ed98eb2a8e3d2d64814d8bd3a41d159aead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Despont?= Date: Tue, 26 Nov 2024 17:32:06 +0100 Subject: [PATCH 2/3] specific checks --- src/bootstrap-table.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bootstrap-table.js b/src/bootstrap-table.js index ff237bbb0..ecf3910f7 100644 --- a/src/bootstrap-table.js +++ b/src/bootstrap-table.js @@ -1116,11 +1116,14 @@ class BootstrapTable { } if (typeof value === 'string' || typeof value === 'number') { - if ( - (this.options.strictSearch && `${value}`.toLowerCase() === searchText) || - (this.options.regexSearch && Utils.regexCompare(value, rawSearchText)) - ) { - return true + if (this.options.strictSearch) { + if ((`${value}`).toLowerCase() === searchText) { + return true + } + } else if (this.options.regexSearch) { + if (Utils.regexCompare(value, rawSearchText)) { + return true + } } else { const largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(-?\d+)?|(-?\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm const matches = largerSmallerEqualsRegex.exec(this.searchText) From 48394f3e8132dcb41d6d06fc4763c7c4cccf2ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Despont?= Date: Tue, 26 Nov 2024 17:47:28 +0100 Subject: [PATCH 3/3] Update bootstrap-table.js --- src/bootstrap-table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap-table.js b/src/bootstrap-table.js index ecf3910f7..f5d9e7c0a 100644 --- a/src/bootstrap-table.js +++ b/src/bootstrap-table.js @@ -1117,7 +1117,7 @@ class BootstrapTable { if (typeof value === 'string' || typeof value === 'number') { if (this.options.strictSearch) { - if ((`${value}`).toLowerCase() === searchText) { + if (`${value}`.toLowerCase() === searchText) { return true } } else if (this.options.regexSearch) {