Skip to content

Commit

Permalink
do not escape doublequotes in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
bblack committed Nov 26, 2015
1 parent 7ecd11b commit 3e9cc31
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/dialects/postgres/string.js
Expand Up @@ -36,7 +36,7 @@ SqlString.escape = function (val, timeZone) {
}
}

val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function (s) {
val = val.replace(/[\0\n\r\b\t\\\'\x1a]/g, function (s) {
switch (s) {
case "\0":
return "\\0";
Expand Down
2 changes: 1 addition & 1 deletion src/dialects/postgres/string.js
Expand Up @@ -34,7 +34,7 @@ SqlString.escape = function(val, timeZone) {
}
}

val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) {
val = val.replace(/[\0\n\r\b\t\\\'\x1a]/g, function(s) {
switch(s) {
case "\0": return "\\0";
case "\n": return "\\n";
Expand Down
17 changes: 12 additions & 5 deletions test/unit/query/builder.js
Expand Up @@ -2441,20 +2441,20 @@ describe("QueryBuilder", function() {
}
})
})

it('has a modify method which accepts a function that can modify the query', function() {
// arbitrary number of arguments can be passed to `.modify(queryBuilder, ...)`,
// arbitrary number of arguments can be passed to `.modify(queryBuilder, ...)`,
// builder is bound to `this`
var withBars = function(queryBuilder, table, fk) {
if(!this || this !== queryBuilder) {
throw 'Expected query builder passed as first argument and bound as `this` context';
}

this
.leftJoin('bars', table + '.' + fk, 'bars.id')
.select('bars.*')
};

testsql(qb().select('foo_id').from('foos').modify(withBars, 'foos', 'bar_id'), {
mysql: {
sql: 'select `foo_id`, `bars`.* from `foos` left join `bars` on `foos`.`bar_id` = `bars`.`id`'
Expand All @@ -2478,7 +2478,14 @@ describe("QueryBuilder", function() {
default: 'select * from "users" where "last_name" = \'O\\\'Brien\'',
});
});


it("escapes double quotes property", function(){
testquery(qb().select('*').from('players').where('name', 'Gerald "Ice" Williams'), {
postgres: 'select * from "players" where "name" = \'Gerald "Ice" Williams\'',
default: 'select * from "players" where "name" = \'Gerald \\"Ice\\" Williams\''
});
});

it("allows join without operator and with value 0 #953", function() {
testsql(qb().select('*').from('users').join('photos', 'photos.id', 0), {
mysql: {
Expand Down

0 comments on commit 3e9cc31

Please sign in to comment.