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

Commit 4dbfb5d1 by Juarez Lustosa Committed by GitHub

fix(query): do not bind $ used within a whole-word (#12250)

1 parent 784712e8
...@@ -84,8 +84,7 @@ class AbstractQuery { ...@@ -84,8 +84,7 @@ class AbstractQuery {
const timeZone = null; const timeZone = null;
const list = Array.isArray(values); const list = Array.isArray(values);
sql = sql.replace(/\B\$(\$|\w+)/g, (match, key) => {
sql = sql.replace(/\$(\$|\w+)/g, (match, key) => {
if ('$' === key) { if ('$' === key) {
return options.skipUnescape ? match : key; return options.skipUnescape ? match : key;
} }
......
...@@ -716,6 +716,13 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -716,6 +716,13 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
}); });
}); });
it('escape where has $ on the middle of characters', function() {
const typeCast = dialect === 'postgres' ? '::int' : '';
return this.sequelize.query(`select $one${typeCast} as foo$bar`, { raw: true, bind: { one: 1 } }).then(result => {
expect(result[0]).to.deep.equal([{ foo$bar: 1 }]);
});
});
if (dialect === 'postgres' || dialect === 'sqlite' || dialect === 'mssql') { if (dialect === 'postgres' || dialect === 'sqlite' || dialect === 'mssql') {
it('does not improperly escape arrays of strings bound to named parameters', function() { it('does not improperly escape arrays of strings bound to named parameters', function() {
return this.sequelize.query('select :stringArray as foo', { raw: true, replacements: { stringArray: ['"string"'] } }).then(result => { return this.sequelize.query('select :stringArray as foo', { raw: true, replacements: { stringArray: ['"string"'] } }).then(result => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!