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 d6daaf1b
authored
Apr 08, 2019
by
Christian Holm
Committed by
Sushant
Apr 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query): add escape of null character for postgres bind parameters (#10716)
1 parent
4c9d18fd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
lib/dialects/postgres/query.js
test/unit/sql/insert.test.js
lib/dialects/postgres/query.js
View file @
d6daaf1
...
...
@@ -20,11 +20,14 @@ class Query extends AbstractQuery {
* @private
*/
static
formatBindParameters
(
sql
,
values
,
dialect
)
{
let
bindParam
=
[];
const
stringReplaceFunc
=
value
=>
typeof
value
===
'string'
?
value
.
replace
(
/
\0
/g
,
'\\0'
)
:
value
;
let
bindParam
;
if
(
Array
.
isArray
(
values
))
{
bindParam
=
values
;
bindParam
=
values
.
map
(
stringReplaceFunc
)
;
sql
=
AbstractQuery
.
formatBindParameters
(
sql
,
values
,
dialect
,
{
skipValueReplace
:
true
})[
0
];
}
else
{
bindParam
=
[];
let
i
=
0
;
const
seen
=
{};
const
replacementFunc
=
(
match
,
key
,
values
)
=>
{
...
...
@@ -33,7 +36,7 @@ class Query extends AbstractQuery {
}
if
(
values
[
key
]
!==
undefined
)
{
i
=
i
+
1
;
bindParam
.
push
(
values
[
key
]
);
bindParam
.
push
(
stringReplaceFunc
(
values
[
key
])
);
seen
[
key
]
=
`$
${
i
}
`
;
return
`$
${
i
}
`
;
}
...
...
test/unit/sql/insert.test.js
View file @
d6daaf1
...
...
@@ -98,6 +98,32 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
});
});
describe
(
'strings'
,
()
=>
{
it
(
'formats null characters correctly when inserting'
,
()
=>
{
const
User
=
Support
.
sequelize
.
define
(
'user'
,
{
username
:
{
type
:
DataTypes
.
STRING
,
field
:
'user_name'
}
},
{
timestamps
:
false
});
expectsql
(
sql
.
insertQuery
(
User
.
tableName
,
{
user_name
:
'null\0test'
},
User
.
rawAttributes
),
{
query
:
{
postgres
:
'INSERT INTO "users" ("user_name") VALUES ($1);'
,
mssql
:
'INSERT INTO [users] ([user_name]) VALUES ($1);'
,
default
:
'INSERT INTO `users` (`user_name`) VALUES ($1);'
},
bind
:
{
postgres
:
[
'null\u0000test'
],
default
:
[
'null\0test'
]
}
});
});
});
describe
(
'bulkCreate'
,
()
=>
{
it
(
'bulk create with onDuplicateKeyUpdate'
,
()
=>
{
const
User
=
Support
.
sequelize
.
define
(
'user'
,
{
...
...
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