不要怂,就是干,撸起袖子干!

Commit d81ea5e4 by Sushant Committed by GitHub

revert "fix(query-interface): incorrect regex escape with json querying (#10615)" (#10623)

This reverts commit 674db195.
1 parent ef18710d
......@@ -19,8 +19,6 @@ const sequelizeError = require('../../errors');
const QuoteHelper = require('./query-generator/helpers/quote');
const nonEscapeOperators = new Set([Op.like, Op.iLike, Op.regexp, Op.iRegexp, Op.notRegexp, Op.notIRegexp]);
/**
* Abstract Query Generator
*
......@@ -952,7 +950,7 @@ class QueryGenerator {
// Users shouldn't have to worry about these args - just give them a function that takes a single arg
const simpleEscape = escVal => SqlString.escape(escVal, this.options.timezone, this.dialect);
value = field.type.stringify(value, { escape: simpleEscape, field, timezone: this.options.timezone, acceptStrings: options.acceptStrings });
value = field.type.stringify(value, { escape: simpleEscape, field, timezone: this.options.timezone, operation: options.operation });
if (field.type.escape === false) {
// The data-type already did the required escaping
......@@ -987,7 +985,7 @@ class QueryGenerator {
this.validate(value, field, options);
if (field.type.bindParam) {
return field.type.bindParam(value, { escape: _.identity, field, timezone: this.options.timezone, bindParam });
return field.type.bindParam(value, { escape: _.identity, field, timezone: this.options.timezone, operation: options.operation, bindParam });
}
}
}
......@@ -2393,8 +2391,9 @@ class QueryGenerator {
comparator = this.OperatorMap[Op.like];
return this._joinKeyValue(key, this.escape(`%${value}%`), comparator, options.prefix);
}
const escapeOptions = {
acceptStrings: nonEscapeOperators.has(prop)
acceptStrings: comparator.includes(this.OperatorMap[Op.like])
};
if (_.isPlainObject(value)) {
......
......@@ -105,7 +105,7 @@ module.exports = BaseTypes => {
class JSONTYPE extends BaseTypes.JSON {
_stringify(value, options) {
return options.acceptsString && typeof value === 'string' ? value
return options.operation === 'where' && typeof value === 'string' ? value
: JSON.stringify(value);
}
}
......
......@@ -124,7 +124,7 @@ module.exports = BaseTypes => {
class JSONTYPE extends BaseTypes.JSON {
_stringify(value, options) {
return options.acceptStrings && typeof value === 'string' ? value : JSON.stringify(value);
return options.operation === 'where' && typeof value === 'string' ? value : JSON.stringify(value);
}
}
......
'use strict';
const { stub } = require('sinon');
const { expect } = require('chai');
const Sequelize = require('../../index');
const Op = Sequelize.Op;
const Promise = Sequelize.Promise;
const Support = require('../support');
const DataTypes = require('../../lib/data-types');
const dialect = Support.getTestDialect();
const chai = require('chai'),
Sequelize = require('../../index'),
Op = Sequelize.Op,
Promise = Sequelize.Promise,
expect = chai.expect,
Support = require('../support'),
DataTypes = require('../../lib/data-types'),
dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('Operators'), () => {
describe('REGEXP', () => {
......@@ -23,9 +23,6 @@ describe(Support.getTestDialectTeaser('Operators'), () => {
name: {
type: DataTypes.STRING,
field: 'full_name'
},
json: {
type: DataTypes.JSON
}
}, {
tableName: 'users',
......@@ -42,9 +39,6 @@ describe(Support.getTestDialectTeaser('Operators'), () => {
},
full_name: {
type: DataTypes.STRING
},
json: {
type: DataTypes.JSON
}
})
]);
......@@ -84,21 +78,6 @@ describe(Support.getTestDialectTeaser('Operators'), () => {
});
});
it('should work with json', function() {
const logging = stub();
return this.User.findOne({
logging,
where: {
json: {
[Op.regexp]: 'test'
}
}
})
.then(() => {
expect(logging.firstCall.args[0]).to.not.include('\\"test\\"');
});
});
it('should properly escape regular expressions', function() {
return this.User.bulkCreate([{
name: 'John'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!