Skip to content

Commit

Permalink
fixes apostrophe issue on mssql dialect (#4077)
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Peabody <jpeabody@axway.com>
  • Loading branch information
wickedest and Jamie Peabody committed Oct 24, 2020
1 parent 162cf2e commit 8faaf9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dialects/mssql/index.js
Expand Up @@ -212,7 +212,7 @@ Object.assign(Client_MSSQL.prototype, {
return '*';
}

return `[${value.replace(/[[\]']+/g, '')}]`;
return `[${value.replace(/[[\]]+/g, '')}]`;
},

// Get a raw connection, called by the `pool` whenever a new
Expand Down
9 changes: 9 additions & 0 deletions test/unit/dialects/mssql.js
Expand Up @@ -30,4 +30,13 @@ describe('MSSQL unit tests', () => {
'select * from [projects] where [id" = 1 UNION SELECT 1, @@version -- --] = ?'
);
});

it("should escape statements with ' correctly", async () => {
const sql = knexInstance('projects')
.where("id]' = 1 UNION SELECT 1, @@version -- --", 1)
.toSQL();
expect(sql.sql).to.equal(
"select * from [projects] where [id' = 1 UNION SELECT 1, @@version -- --] = ?"
);
});
});

0 comments on commit 8faaf9c

Please sign in to comment.