From f3bfd7a78352aa5a1ef40e7c19c3c474f7585d18 Mon Sep 17 00:00:00 2001 From: rkraja Date: Sun, 10 Sep 2023 20:24:52 -0500 Subject: [PATCH 1/4] fixes #1734. LIKE will not work correctly when there is a line break --- src/15utility.js | 4 ++-- test/test244.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/15utility.js b/src/15utility.js index 51345897e9..b1f06c27d7 100755 --- a/src/15utility.js +++ b/src/15utility.js @@ -1197,7 +1197,7 @@ var like = (utils.like = function (pattern, value, escape) { } else if (c === '[' || c === ']') { s += c; } else if (c === '%') { - s += '.*'; + s += '[\\s\\S]*'; } else if (c === '_') { s += '.'; } else if ('/.*+?|(){}'.indexOf(c) > -1) { @@ -1211,7 +1211,7 @@ var like = (utils.like = function (pattern, value, escape) { s += '$'; // if(value == undefined) return false; //console.log(s,value,(value||'').search(RegExp(s))>-1); - return ('' + (value || '')).toUpperCase().search(RegExp(s.toUpperCase())) > -1; + return ('' + (value || '')).search(RegExp(s, 'i')) > -1; }); utils.glob = function (value, pattern) { diff --git a/test/test244.js b/test/test244.js index 0c8bd3631b..f6ceac2a45 100644 --- a/test/test244.js +++ b/test/test244.js @@ -16,7 +16,7 @@ describe('Test 244 Case-insensitive LIKE', function () { var res = alasql('SELECT b FROM ? WHERE a LIKE "T%"', [data]); //console.log(res); - assert(res, [{b: 'second'}, {b: 'THIRD'}]); + assert.deepEqual(res, [{b: 'second'}, {b: 'THIRD'}]); done(); }); @@ -33,7 +33,7 @@ describe('Test 244 Case-insensitive LIKE', function () { var res = alasql('SELECT * FROM ? WHERE a LIKE "m%"', [data]); //console.log(res); - assert(res, [{a: 'MOSCOW'}, {a: 'MINSK'}]); + assert.deepEqual(res, [{a: 'MOSCOW'}, {a: 'MINSK'}]); done(); }); }); From af0079c48ff53673b8858304f17a13050c20ec27 Mon Sep 17 00:00:00 2001 From: rkraja Date: Sun, 10 Sep 2023 20:34:30 -0500 Subject: [PATCH 2/4] fixes #1734. LIKE will not work correctly when there is a line break --- test/test1734.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/test1734.js diff --git a/test/test1734.js b/test/test1734.js new file mode 100644 index 0000000000..fe44ed5dd5 --- /dev/null +++ b/test/test1734.js @@ -0,0 +1,23 @@ +if (typeof exports === 'object') { + var assert = require('assert'); + var alasql = require('..'); +} else { + __dirname = '.'; +} + +var test = '1666'; +describe('Test' + test + 'Newline characters in like', function () { + it('1. LIKE', function (done) { + var data = [ + {a: 'one', b: 'first'}, + {a: 'two', b: 'second\n\ritem'}, + {a: 'THREE', b: 'THIRD'}, + ]; + + var res = alasql('SELECT b FROM ? WHERE a LIKE "T%"', [data]); + + //console.log(res); + assert.deepEqual(res, [{b: 'second\n\ritem'}, {b: 'THIRD'}]); + done(); + }); +}); From 4d405cf982e5cd070ac42e5fd2e2f9843e8cc6e8 Mon Sep 17 00:00:00 2001 From: rkraja Date: Tue, 12 Sep 2023 07:28:17 -0500 Subject: [PATCH 3/4] improve spec --- test/test1734.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/test1734.js b/test/test1734.js index fe44ed5dd5..f6484a9030 100644 --- a/test/test1734.js +++ b/test/test1734.js @@ -11,13 +11,29 @@ describe('Test' + test + 'Newline characters in like', function () { var data = [ {a: 'one', b: 'first'}, {a: 'two', b: 'second\n\ritem'}, + {a: 'THREE', b: 'THI\n\rRD'}, + ]; + + var res = alasql('SELECT b FROM ? WHERE b LIKE "t%"', [data]); + + //console.log(res); + assert.deepEqual(res, [{b: 'THI\n\rRD'}]); + done(); + }); + + it('2. LIKE', function (done) { + var data = [ + {a: 'one', b: 'Nine'}, + {a: 'two', b: 'second\n\ritem'}, {a: 'THREE', b: 'THIRD'}, + {a: 'FOUR', b: '\n\rFifth'}, + {a: 'FIVE', b: 'Six\nth'}, ]; - var res = alasql('SELECT b FROM ? WHERE a LIKE "T%"', [data]); + var res = alasql('SELECT b FROM ? WHERE b LIKE "%T%"', [data]); //console.log(res); - assert.deepEqual(res, [{b: 'second\n\ritem'}, {b: 'THIRD'}]); + assert.deepEqual(res, [{b: 'second\n\ritem'}, {b: 'THIRD'}, {b: '\n\rFifth'}, {b: 'Six\nth'}]); done(); }); }); From 0bc5340cab8228a0796e7013170ecc216e4a8651 Mon Sep 17 00:00:00 2001 From: rkraja Date: Thu, 14 Sep 2023 20:29:27 -0500 Subject: [PATCH 4/4] fix for PR comment --- src/15utility.js | 2 +- test/test1734.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/15utility.js b/src/15utility.js index b1f06c27d7..a3f79d05ab 100755 --- a/src/15utility.js +++ b/src/15utility.js @@ -1211,7 +1211,7 @@ var like = (utils.like = function (pattern, value, escape) { s += '$'; // if(value == undefined) return false; //console.log(s,value,(value||'').search(RegExp(s))>-1); - return ('' + (value || '')).search(RegExp(s, 'i')) > -1; + return ('' + (value ?? '')).search(RegExp(s, 'i')) > -1; }); utils.glob = function (value, pattern) { diff --git a/test/test1734.js b/test/test1734.js index f6484a9030..4bf1814735 100644 --- a/test/test1734.js +++ b/test/test1734.js @@ -36,4 +36,18 @@ describe('Test' + test + 'Newline characters in like', function () { assert.deepEqual(res, [{b: 'second\n\ritem'}, {b: 'THIRD'}, {b: '\n\rFifth'}, {b: 'Six\nth'}]); done(); }); + + it('3. LIKE', function (done) { + var data = [ + {a: 'one', b: 0}, + {a: 'three', b: 'three'}, + {a: 'two', b: '0ne'}, + ]; + + var res = alasql('SELECT b FROM ? WHERE b LIKE "0%"', [data]); + + //console.log(res); + assert.deepEqual(res, [{b: 0}, {b: '0ne'}]); + done(); + }); });