Skip to content

Commit ee421e6

Browse files
committed
Bug: SqlString.id was not passing raw qualified identifiers
Also improved test coverage of branch in lib/SqlString.js.
1 parent 0a1089b commit ee421e6

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/SqlString.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var CHARS_ESCAPE_MAP = {
1414
'\'' : '\\\'',
1515
'\\' : '\\\\'
1616
};
17-
var ONE_ID_PATTERN = '^`(?:[^`]|``)+`$'; // TODO(mikesamuel): Should allow ``?
17+
var ONE_ID_PATTERN = '`(?:[^`]|``)+`'; // TODO(mikesamuel): Should allow ``?
1818
// One or more Identifiers separated by dots.
1919
var QUALIFIED_ID_REGEXP = new RegExp(
2020
'^' + ONE_ID_PATTERN + '(?:[.]' + ONE_ID_PATTERN + ')*$');

test/unit/test-SqlString.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,18 @@ test('SqlString.format', {
259259

260260
'double quest marks passes pre-escaped id': function () {
261261
var sql = SqlString.format(
262-
'SELECT * FROM ?? WHERE id = ?',
263-
[SqlString.identifier('table'), 42]);
264-
assert.equal(sql, 'SELECT * FROM `table` WHERE id = 42');
262+
'SELECT ?? FROM ?? WHERE id = ?',
263+
[SqlString.identifier('table.id'),
264+
SqlString.identifier('table'), 42]);
265+
assert.equal(sql, 'SELECT `table`.`id` FROM `table` WHERE id = 42');
266+
},
267+
268+
'double quest marks rejects invalid raw': function () {
269+
assert.throws(function () {
270+
SqlString.format(
271+
'SELECT * FROM ?? WHERE id = 42',
272+
[SqlString.raw('NOW()')]);
273+
});
265274
},
266275

267276
'extra question marks are left untouched': function() {

0 commit comments

Comments
 (0)