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

Commit 850c7fd0 by Sushant Committed by GitHub

feat(postgres): enable standard conforming strings when required (#10746)

1 parent 7c3c18a9
...@@ -256,7 +256,10 @@ class ConnectionManager { ...@@ -256,7 +256,10 @@ class ConnectionManager {
//avoiding a useless round trip //avoiding a useless round trip
if (this.sequelize.options.databaseVersion === 0) { if (this.sequelize.options.databaseVersion === 0) {
return this.sequelize.databaseVersion(_options).then(version => { return this.sequelize.databaseVersion(_options).then(version => {
this.sequelize.options.databaseVersion = semver.valid(version) ? version : this.defaultVersion; const parsedVersion = _.get(semver.coerce(version), 'version') || version;
this.sequelize.options.databaseVersion = semver.valid(parsedVersion)
? parsedVersion
: this.defaultVersion;
this.versionPromise = null; this.versionPromise = null;
return this._disconnect(connection); return this._disconnect(connection);
}); });
......
...@@ -122,6 +122,23 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -122,6 +122,23 @@ class ConnectionManager extends AbstractConnectionManager {
let responded = false; let responded = false;
const connection = new this.lib.Client(connectionConfig); const connection = new this.lib.Client(connectionConfig);
const parameterHandler = message => {
switch (message.parameterName) {
case 'server_version':
if (this.sequelize.options.databaseVersion === 0) {
const version = semver.coerce(message.parameterValue).version;
this.sequelize.options.databaseVersion = semver.valid(version)
? version
: this.defaultVersion;
}
break;
case 'standard_conforming_strings':
connection['standard_conforming_strings'] = message.parameterValue;
break;
}
};
const endHandler = () => { const endHandler = () => {
debug('connection timeout'); debug('connection timeout');
if (!responded) { if (!responded) {
...@@ -133,8 +150,19 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -133,8 +150,19 @@ class ConnectionManager extends AbstractConnectionManager {
// node-postgres does not treat this as an error since no active query was ever emitted // node-postgres does not treat this as an error since no active query was ever emitted
connection.once('end', endHandler); connection.once('end', endHandler);
if (!this.sequelize.config.native) {
// Receive various server parameters for further configuration
connection.connection.on('parameterStatus', parameterHandler);
}
connection.connect(err => { connection.connect(err => {
responded = true; responded = true;
if (!this.sequelize.config.native) {
// remove parameter handler
connection.connection.removeListener('parameterStatus', parameterHandler);
}
if (err) { if (err) {
if (err.code) { if (err.code) {
switch (err.code) { switch (err.code) {
...@@ -166,11 +194,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -166,11 +194,7 @@ class ConnectionManager extends AbstractConnectionManager {
}).tap(connection => { }).tap(connection => {
let query = ''; let query = '';
if ( if (connection['standard_conforming_strings'] !== 'on') {
this.sequelize.options.databaseVersion !== 0
&& semver.gte(this.sequelize.options.databaseVersion, '8.2.0')
&& semver.lt(this.sequelize.options.databaseVersion, '9.1.0')
) {
// Disable escape characters in strings // Disable escape characters in strings
// see https://github.com/sequelize/sequelize/issues/3545 (security issue) // see https://github.com/sequelize/sequelize/issues/3545 (security issue)
// see https://www.postgresql.org/docs/current/static/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS // see https://www.postgresql.org/docs/current/static/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!