Skip to content

Commit 87605e2

Browse files
committed
Fix #684 : getSQL issue with consecutive dollar signs
1 parent 0d41d9c commit 87605e2

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"jit-grunt": "^0.10.0",
5151
"qunit": "^2.5.1",
5252
"selectize": "^0.12.4",
53-
"sql-parser-mistic": "^1.2.0",
53+
"sql-parser-mistic": "^1.2.2",
5454
"time-grunt": "^1.3.0"
5555
},
5656
"keywords": [
@@ -69,6 +69,7 @@
6969
"url": "https://github.com/mistic100/jQuery-QueryBuilder/issues"
7070
},
7171
"scripts": {
72+
"serve": "grunt serve",
7273
"test": "grunt test"
7374
}
7475
}

src/plugins/sql-support/plugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ QueryBuilder.extend(/** @lends module:plugins.SqlSupport.prototype */ {
328328
}
329329

330330
var sqlFn = function(v) {
331-
return sql.op.replace('?', v);
331+
return sql.op.replace('?', function() {
332+
return v;
333+
});
332334
};
333335

334336
/**

tests/plugins.sql-support.module.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,35 @@ $(function() {
131131
);
132132
});
133133

134+
QUnit.test('Special chars', function(assert) {
135+
// PhantomJS is broken https://github.com/ariya/phantomjs/issues/14921
136+
if (!!window._phantom) {
137+
assert.ok(true, 'Test ignore in PhantomJS');
138+
return;
139+
}
140+
141+
var chars = ['\'', '"', '$1', '$$', '$&', '$`', '$\''];
142+
143+
var sql = "name = '\\'' AND name = '\\\"' AND name = '$1' AND " +
144+
"name = '$$' AND name = '$&' AND name = '$`' AND name = '$\\''";
145+
146+
$b.queryBuilder({
147+
filters: basic_filters,
148+
rules: chars.map(function(char) {
149+
return {
150+
id: 'name',
151+
value: char
152+
};
153+
})
154+
});
155+
156+
assert.equal(
157+
$b.queryBuilder('getSQL').sql,
158+
sql,
159+
'Should output SQL with escaped special chars'
160+
);
161+
});
162+
134163
QUnit.test('All operators', function(assert) {
135164
$b.queryBuilder({
136165
filters: basic_filters,

0 commit comments

Comments
 (0)