From 86bc84a2ad6d0f463af112090c26163deea56a35 Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 30 Dec 2018 22:09:14 +0100 Subject: [PATCH] better detection of float parameter in label filters, fixes #265 --- src/services/build_search_query.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/build_search_query.js b/src/services/build_search_query.js index e4464400e..a7c3d3a43 100644 --- a/src/services/build_search_query.js +++ b/src/services/build_search_query.js @@ -23,9 +23,15 @@ module.exports = function(attributeFilters) { whereParams.push(filter.value); } else if ([">", ">=", "<", "<="].includes(filter.operator)) { - const floatParam = parseFloat(filter.value); + let floatParam; - if (isNaN(floatParam)) { + // from https://stackoverflow.com/questions/12643009/regular-expression-for-floating-point-numbers + if (/^[+-]?([0-9]*[.])?[0-9]+$/.test(filter.value)) { + floatParam = parseFloat(filter.value); + } + + if (floatParam === undefined || isNaN(floatParam)) { + // if the value can't be parsed as float then we assume that string comparison should be used instead of numeric where += `attribute${i}.value ${filter.operator} ?`; whereParams.push(filter.value); }