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 1fd04f79
authored
Sep 24, 2014
by
Sveinn Fannar Kristjansson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Escape value passed to sequelize.json
1 parent
dc976b4a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
7 deletions
lib/dialects/abstract/query-generator.js
lib/utils.js
test/utils.test.js
lib/dialects/abstract/query-generator.js
View file @
1fd04f7
...
@@ -1268,7 +1268,7 @@ module.exports = (function() {
...
@@ -1268,7 +1268,7 @@ module.exports = (function() {
result
=
(
value
===
'NULL'
)
?
key
+
' IS NULL'
:
[
key
,
value
].
join
(
'='
);
result
=
(
value
===
'NULL'
)
?
key
+
' IS NULL'
:
[
key
,
value
].
join
(
'='
);
}
}
}
else
if
(
smth
instanceof
Utils
.
json
)
{
}
else
if
(
smth
instanceof
Utils
.
json
)
{
result
=
smth
.
toString
();
result
=
smth
.
toString
(
this
);
}
else
if
(
Utils
.
_
.
isPlainObject
(
smth
))
{
}
else
if
(
Utils
.
_
.
isPlainObject
(
smth
))
{
if
(
prepend
)
{
if
(
prepend
)
{
if
(
tableName
)
options
.
keysEscaped
=
true
;
if
(
tableName
)
options
.
keysEscaped
=
true
;
...
...
lib/utils.js
View file @
1fd04f7
...
@@ -625,7 +625,7 @@ Utils.col.prototype.toString = function(queryGenerator, parentModel) {
...
@@ -625,7 +625,7 @@ Utils.col.prototype.toString = function(queryGenerator, parentModel) {
return
queryGenerator
.
quote
(
this
.
col
,
parentModel
);
return
queryGenerator
.
quote
(
this
.
col
,
parentModel
);
};
};
Utils
.
json
.
prototype
.
toString
=
function
()
{
Utils
.
json
.
prototype
.
toString
=
function
(
queryGenerator
)
{
var
_
=
Utils
.
_
;
var
_
=
Utils
.
_
;
// A recursive parser for nested where conditions
// A recursive parser for nested where conditions
...
@@ -666,7 +666,7 @@ Utils.json.prototype.toString = function () {
...
@@ -666,7 +666,7 @@ Utils.json.prototype.toString = function () {
}
}
if
(
this
.
value
)
{
if
(
this
.
value
)
{
str
+=
util
.
format
(
" =
'%s'"
,
this
.
value
);
str
+=
util
.
format
(
" =
%s"
,
queryGenerator
.
escape
(
this
.
value
)
);
}
}
return
str
;
return
str
;
...
...
test/utils.test.js
View file @
1fd04f7
...
@@ -148,6 +148,8 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
...
@@ -148,6 +148,8 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
});
});
describe
(
'json'
,
function
()
{
describe
(
'json'
,
function
()
{
var
queryGeneratorStub
=
{
escape
:
function
(
value
)
{
return
"'"
+
value
+
"'"
;
}
};
it
(
'successfully parses a complex nested condition hash'
,
function
()
{
it
(
'successfully parses a complex nested condition hash'
,
function
()
{
var
conditions
=
{
var
conditions
=
{
metadata
:
{
metadata
:
{
...
@@ -156,23 +158,24 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
...
@@ -156,23 +158,24 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
},
},
another_json_field
:
{
x
:
1
}
another_json_field
:
{
x
:
1
}
};
};
expect
((
new
Utils
.
json
(
conditions
)).
toString
()).
to
.
deep
.
equal
(
"metadata#>>'{language}' = 'icelandic' and metadata#>>'{pg_rating,dk}' = 'G' and another_json_field#>>'{x}' = '1'"
);
var
expected
=
"metadata#>>'{language}' = 'icelandic' and metadata#>>'{pg_rating,dk}' = 'G' and another_json_field#>>'{x}' = '1'"
;
expect
((
new
Utils
.
json
(
conditions
)).
toString
(
queryGeneratorStub
)).
to
.
deep
.
equal
(
expected
);
});
});
it
(
'successfully parses a string using dot notation'
,
function
()
{
it
(
'successfully parses a string using dot notation'
,
function
()
{
var
path
=
'metadata.pg_rating.dk'
;
var
path
=
'metadata.pg_rating.dk'
;
expect
((
new
Utils
.
json
(
path
)).
toString
()).
to
.
equal
(
"metadata#>>'{pg_rating,dk}'"
);
expect
((
new
Utils
.
json
(
path
)).
toString
(
queryGeneratorStub
)).
to
.
equal
(
"metadata#>>'{pg_rating,dk}'"
);
});
});
it
(
'allows postgres json syntax'
,
function
()
{
it
(
'allows postgres json syntax'
,
function
()
{
var
path
=
'metadata->pg_rating->>dk'
;
var
path
=
'metadata->pg_rating->>dk'
;
expect
((
new
Utils
.
json
(
path
)).
toString
()).
to
.
equal
(
path
);
expect
((
new
Utils
.
json
(
path
)).
toString
(
queryGeneratorStub
)).
to
.
equal
(
path
);
});
});
it
(
'can take a value to compare against'
,
function
()
{
it
(
'can take a value to compare against'
,
function
()
{
var
path
=
'metadata.pg_rating.is'
;
var
path
=
'metadata.pg_rating.is'
;
var
value
=
'U'
;
var
value
=
'U'
;
expect
((
new
Utils
.
json
(
path
,
value
)).
toString
()).
to
.
equal
(
"metadata#>>'{pg_rating,is}' = 'U'"
);
expect
((
new
Utils
.
json
(
path
,
value
)).
toString
(
queryGeneratorStub
)).
to
.
equal
(
"metadata#>>'{pg_rating,is}' = 'U'"
);
});
});
});
});
...
...
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