diff --git a/index.js b/index.js index f652630..866f0ea 100644 --- a/index.js +++ b/index.js @@ -101,14 +101,14 @@ class SequelizeQueryStringParser { */ find (expression) { let where = {} - if (expression.match(/(([\w|.]+)\s(\w+)\s([\w|\s|%|_]+),?)+/)) { - let parts = (expression).split(',') + if (expression.match(new RegExp(`(([\\w|.]+)\\s(\\w+)\\s([\\w|\\s|%|_|${utf8letters}]+),?)+`))) { + 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 7dc0eb0..3fc1751 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.2", "description": "Convert the request query string into sequelize compatible where and sort clauses.", "main": "index.js", "engines": { 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'