From e725df8c78c39a44e3cafab426eecb55c9946350 Mon Sep 17 00:00:00 2001 From: wrq Date: Tue, 16 Apr 2019 16:36:29 +0800 Subject: [PATCH 1/3] fix bug that return empty where if filter contains utf8letter --- index.js | 2 +- test/test_filter.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f652630..27b0a2b 100644 --- a/index.js +++ b/index.js @@ -101,7 +101,7 @@ class SequelizeQueryStringParser { */ find (expression) { let where = {} - if (expression.match(/(([\w|.]+)\s(\w+)\s([\w|\s|%|_]+),?)+/)) { + if (expression.match(new RegExp(`(([\\w|.]+)\\s(\\w+)\\s([\\w|\\s|%|_|${utf8letters}]+),?)+`))) { let parts = (expression).split(',') const operators = this.operators() for (let i = 0; i < parts.length; i++) { diff --git a/test/test_filter.js b/test/test_filter.js index 9207663..e0fde81 100644 --- a/test/test_filter.js +++ b/test/test_filter.js @@ -9,6 +9,18 @@ const sqs = require('../index.js') describe('Convert query strings into Sequelize find queries.', (done) => { + it('(eq) Find convert equal operator with utf8letter to where.', () => { + let qs = 'geoId eq 测试' + let where = sqs.find(qs) + expect(where).to.be.instanceof(Object) + expect(where).to.have.deep.property('geoId.$eq', '测试') + // test symbolic + where = sqsSym.find(qs) + expect(where).to.be.instanceof(Object) + expect(where).to.have.property('geoId') + expect(where.geoId).to.have.property(sequelize.Op.eq, '测试') + }) + // test string, integer and UUID it('(eq) Find convert equal operator to where.', () => { let qs = 'geoId eq 4301' From e6a806971b6dd9a34497c67981872cb252590cf4 Mon Sep 17 00:00:00 2001 From: wrq Date: Tue, 21 May 2019 15:28:43 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7dc0eb0..e343e82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "sequelize-querystring", - "version": "0.10.0", + "name": "sequelize-querystring-utf8", + "version": "0.10.1", "description": "Convert the request query string into sequelize compatible where and sort clauses.", "main": "index.js", "engines": { From b25367469cfbc5ee02e34d44ce174048c7a6d914 Mon Sep 17 00:00:00 2001 From: wrq Date: Fri, 31 May 2019 10:01:06 +0800 Subject: [PATCH 3/3] =?UTF-8?q?rhs=E5=8C=B9=E9=85=8D=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=AD=97=E7=AC=A6,=20split=20/,\s/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 27b0a2b..866f0ea 100644 --- a/index.js +++ b/index.js @@ -102,13 +102,13 @@ class SequelizeQueryStringParser { find (expression) { let where = {} if (expression.match(new RegExp(`(([\\w|.]+)\\s(\\w+)\\s([\\w|\\s|%|_|${utf8letters}]+),?)+`))) { - let parts = (expression).split(',') + let parts = (expression).split(/,\s/) const operators = this.operators() for (let i = 0; i < parts.length; i++) { // build a regexp to match filter expressions const lhs = '[\\w|.]+' const op = '\\w+' - const rhs = `[A-Za-z0-9.+@:/()%_\\s\\-\\xAA\\xB5\\xBA${utf8letters}]+` + const rhs = `.+` const expressionRegExp = new RegExp(`(${lhs})\\s+(${op})\\s+(${rhs})`) if (parts[i].match(expressionRegExp)) { let prop = RegExp.$1 diff --git a/package.json b/package.json index e343e82..3fc1751 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sequelize-querystring-utf8", - "version": "0.10.1", + "version": "0.10.2", "description": "Convert the request query string into sequelize compatible where and sort clauses.", "main": "index.js", "engines": {