do not escape doublequotes in postgres

This commit is contained in:
Brian Black 2015-11-13 15:47:27 -05:00
parent 332ed3b811
commit 27b0a57823
3 changed files with 14 additions and 7 deletions

View File

@ -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 '\u0000':
return '\\0';

View File

@ -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";

View File

@ -2458,20 +2458,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`'
@ -2495,7 +2495,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: {