Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit c9d3a978
authored
Apr 10, 2019
by
Sushant
Committed by
Erik Seliger
May 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(postgres): enable standard conforming strings when required (#10746)
1 parent
73d7a65f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
3 deletions
lib/dialects/abstract/connection-manager.js
lib/dialects/postgres/connection-manager.js
lib/dialects/abstract/connection-manager.js
View file @
c9d3a97
...
@@ -256,9 +256,11 @@ class ConnectionManager {
...
@@ -256,9 +256,11 @@ class ConnectionManager {
_options
.
logging
.
__testLoggingFn
=
true
;
_options
.
logging
.
__testLoggingFn
=
true
;
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
);
});
});
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
...
...
lib/dialects/postgres/connection-manager.js
View file @
c9d3a97
...
@@ -106,9 +106,35 @@ class ConnectionManager extends AbstractConnectionManager {
...
@@ -106,9 +106,35 @@ class ConnectionManager extends AbstractConnectionManager {
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
connection
=
new
this
.
lib
.
Client
(
connectionConfig
);
const
connection
=
new
this
.
lib
.
Client
(
connectionConfig
);
let
responded
=
false
;
let
responded
=
false
;
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
;
}
};
if
(
!
this
.
sequelize
.
config
.
native
)
{
// Receive various server parameters for further configuration
connection
.
connection
.
on
(
'parameterStatus'
,
parameterHandler
);
}
connection
.
connect
(
err
=>
{
connection
.
connect
(
err
=>
{
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
)
{
...
@@ -155,7 +181,10 @@ class ConnectionManager extends AbstractConnectionManager {
...
@@ -155,7 +181,10 @@ class ConnectionManager extends AbstractConnectionManager {
// Disable escape characters in strings, see https://github.com/sequelize/sequelize/issues/3545
// Disable escape characters in strings, see https://github.com/sequelize/sequelize/issues/3545
let
query
=
''
;
let
query
=
''
;
if
(
this
.
sequelize
.
options
.
databaseVersion
!==
0
&&
semver
.
gte
(
this
.
sequelize
.
options
.
databaseVersion
,
'8.2.0'
))
{
if
(
connection
[
'standard_conforming_strings'
]
!==
'on'
)
{
// Disable escape characters in strings
// 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
query
+=
'SET standard_conforming_strings=on;'
;
query
+=
'SET standard_conforming_strings=on;'
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment