alasql 2.0.8 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/alasql-cli.js +1 -1
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql-worker.min.js +1 -1
- package/dist/alasql.fs.js +240 -33
- package/dist/alasql.js +240 -33
- package/dist/alasql.min.js +37 -2
- package/package.json +1 -1
package/bin/alasql-cli.js
CHANGED
package/dist/alasql-worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.0.
|
|
1
|
+
//! AlaSQL v2.0.10 | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.0.
|
|
4
|
+
@version 2.0.10
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//! AlaSQL v2.0.
|
|
1
|
+
//! AlaSQL v2.0.10 | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
2
|
!function(r,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():r.alasql=e()}(this,function(){function i(r,e,o){"function"==typeof(e=e||[])&&(scope=o,o=e,e=[]),"object"!=typeof e&&(e=[e]);var t=i.lastid++;i.buffer[t]=o,i.webworker.postMessage({id:t,sql:r,params:e})}var a;if(i.options={},i.options.progress=function(){},isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)},i.promise=function(){throw new Error("Please include a Promise/A+ library")},"undefined"!=typeof Promise&&(a=function(r,e,n,s){return new Promise(function(o,t){i(r,e,function(r,e){e?t(e):(n&&s&&!1!==i.options.progress&&i.options.progress(n,s),o(r))})})},i.promise=function(r,e){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return a(r,e);if(!isArray(r)||r.length<1||void 0!==e)throw new Error("Error in .promise parameters");var o=r;if(!(o.length<1)){for(var t,n,s=[],i=0;i<o.length;i++){if("string"==typeof(n=o[i])&&(n=[n]),!isArray(n)||n.length<1||2<n.length)throw new Error("Error in .promise parameter");t=n[0],n=n[1]||void 0,s.push(a(t,n,i,o.length))}return Promise.all(s)}}),i=i||!1)return i.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(i.worker=function(r,e,o){if(void 0===(r=!0===r?void 0:r))for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){if("alasql-worker.js"===t[n].src.substr(-16).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===t[n].src.substr(-20).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-20)+"alasql.min.js";break}if("alasql.js"===t[n].src.substr(-9).toLowerCase()){r=t[n].src;break}if("alasql.min.js"===t[n].src.substr(-13).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-13)+"alasql.min.js";break}}if(void 0===r)throw new Error("Path to alasql.js is not specified");var s;!1!==r?(s=(s="importScripts('")+r+"');self.onmessage = function(event) {alasql(event.data.sql,event.data.params, function(data){postMessage({id:event.data.id, data:data});});}",s=new Blob([s],{type:"text/plain"}),i.webworker=new Worker(URL.createObjectURL(s)),i.webworker.onmessage=function(r){var e=r.data.id;i.buffer[e](r.data.data),delete i.buffer[e]},i.webworker.onerror=function(r){throw r},1<arguments.length&&i("REQUIRE "+e.map(function(r){return'"'+r+'"'}).join(","),[],o)):!1===r&&delete i.webworker}),i.lastid=0,i.buffer={},i.worker(),i;throw new Error("alasql was not found")});
|
package/dist/alasql.fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.0.
|
|
1
|
+
//! AlaSQL v2.0.10 | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.0.
|
|
4
|
+
@version 2.0.10
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -142,7 +142,7 @@ var alasql = function(sql, params, cb, scope) {
|
|
|
142
142
|
Current version of alasql
|
|
143
143
|
@constant {string}
|
|
144
144
|
*/
|
|
145
|
-
alasql.version = '2.0.
|
|
145
|
+
alasql.version = '2.0.10';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -2495,7 +2495,7 @@ next:function () {
|
|
|
2495
2495
|
|
|
2496
2496
|
// return next match that has a token
|
|
2497
2497
|
lex:function lex () {
|
|
2498
|
-
var r = this.next();
|
|
2498
|
+
var r = this.next();if(r&&/^(N?['"]__proto__['"]|\[__proto__\]|`__proto__`|__proto__)$/i.test(this.yytext))throw new Error("__proto__ is not allowed");
|
|
2499
2499
|
if (r) {
|
|
2500
2500
|
return r;
|
|
2501
2501
|
} else {
|
|
@@ -4450,9 +4450,201 @@ alasql.parser.parseError = function (str, hash) {
|
|
|
4450
4450
|
}
|
|
4451
4451
|
*/
|
|
4452
4452
|
alasql.parse = function (sql) {
|
|
4453
|
-
|
|
4453
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
4454
|
+
checkSqlNames(ast);
|
|
4455
|
+
return ast;
|
|
4454
4456
|
};
|
|
4455
4457
|
|
|
4458
|
+
/*
|
|
4459
|
+
A name from the SQL text is pasted into generated code between single quotes, so a name that
|
|
4460
|
+
holds a quote, a backslash or a line break would end the string and make the rest code
|
|
4461
|
+
(GHSA-67vj-hh8j-j94f). Such a name is refused here, once, after parsing. A name is a table,
|
|
4462
|
+
column, database, view, index, trigger or CTE name, a variable (and the keys of its path) and a
|
|
4463
|
+
table alias. The alias of a column in the select list is not a name: it is a key of the result,
|
|
4464
|
+
and the code that writes it escapes it. Strings, numbers, parameters, JavaScript and the keys
|
|
4465
|
+
of a JSON value are data, not names.
|
|
4466
|
+
*/
|
|
4467
|
+
var checkSqlNames = (function () {
|
|
4468
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
4469
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
4470
|
+
var nameKeys = {
|
|
4471
|
+
as: 1,
|
|
4472
|
+
columnid: 1,
|
|
4473
|
+
tableid: 1,
|
|
4474
|
+
databaseid: 1,
|
|
4475
|
+
viewid: 1,
|
|
4476
|
+
indexid: 1,
|
|
4477
|
+
trigger: 1,
|
|
4478
|
+
variable: 1,
|
|
4479
|
+
dropcolumn: 1,
|
|
4480
|
+
renamecolumn: 1,
|
|
4481
|
+
renameto: 1,
|
|
4482
|
+
to: 1,
|
|
4483
|
+
tocolumnid: 1,
|
|
4484
|
+
forcolumnid: 1,
|
|
4485
|
+
};
|
|
4486
|
+
var nameListKeys = {columns: 1, fkcolumns: 1, props: 1};
|
|
4487
|
+
|
|
4488
|
+
function checkName(name) {
|
|
4489
|
+
if (badName.test(name)) throw new SyntaxError('Not a valid name: ' + name);
|
|
4490
|
+
}
|
|
4491
|
+
|
|
4492
|
+
// ORDER BY: a name that equals an alias of the select list is that alias and is allowed (the code
|
|
4493
|
+
// escapes it), anything else is checked. (In this version a string in ORDER BY is a constant.)
|
|
4494
|
+
function checkOrder(columns, order) {
|
|
4495
|
+
var aliases = {};
|
|
4496
|
+
(columns || []).forEach(function (col) {
|
|
4497
|
+
if (col && typeof col.as === 'string') aliases[col.as] = true;
|
|
4498
|
+
});
|
|
4499
|
+
order.forEach(function (ord) {
|
|
4500
|
+
var e = ord && ord.expression;
|
|
4501
|
+
var name;
|
|
4502
|
+
if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
4503
|
+
if (typeof name === 'string') {
|
|
4504
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
4505
|
+
return;
|
|
4506
|
+
}
|
|
4507
|
+
checkNames(ord, false, false);
|
|
4508
|
+
});
|
|
4509
|
+
}
|
|
4510
|
+
|
|
4511
|
+
// The alias of an entry of the select list, of SEARCH RETURNS and of CREATE GRAPH is a key of
|
|
4512
|
+
// the result or a variable and is allowed. The name of an entry of WITH is a table name; in a
|
|
4513
|
+
// graph item, name is data.
|
|
4514
|
+
function entryOf(node, key) {
|
|
4515
|
+
var yy = alasql.yy;
|
|
4516
|
+
if (
|
|
4517
|
+
(node instanceof yy.Select && key === 'columns') ||
|
|
4518
|
+
(node instanceof yy.CreateGraph && key === 'graph') ||
|
|
4519
|
+
(node.srchid === 'RETURN' && key === 'args')
|
|
4520
|
+
)
|
|
4521
|
+
return 'alias';
|
|
4522
|
+
if (node instanceof yy.WithSelect && key === 'withs') return 'with';
|
|
4523
|
+
return '';
|
|
4524
|
+
}
|
|
4525
|
+
|
|
4526
|
+
// Names that never reach generated code: they are used only at run time, as the key of a
|
|
4527
|
+
// database, a table, an index, a trigger or a variable, so the walk leaves them alone and such a
|
|
4528
|
+
// name keeps working. freeKeys are names of the node itself, freeChild are children whose own
|
|
4529
|
+
// names are free (what they hold is still walked), and skipChild are children that are not
|
|
4530
|
+
// walked at all (PIVOT and UNPIVOT work on the result and build no code).
|
|
4531
|
+
var varValueFree = false;
|
|
4532
|
+
var intoVarFree = false;
|
|
4533
|
+
var freeKeys = [
|
|
4534
|
+
['CreateIndex', {indexid: 1}],
|
|
4535
|
+
['DropIndex', {indexid: 1}],
|
|
4536
|
+
['Reindex', {indexid: 1}],
|
|
4537
|
+
['CreateTrigger', {trigger: 1}],
|
|
4538
|
+
['DropTrigger', {trigger: 1}],
|
|
4539
|
+
['CreateDatabase', {databaseid: 1, as: 1}],
|
|
4540
|
+
['AttachDatabase', {databaseid: 1, as: 1}],
|
|
4541
|
+
['DetachDatabase', {databaseid: 1}],
|
|
4542
|
+
['DropDatabase', {databaseid: 1}],
|
|
4543
|
+
['ShowTables', {databaseid: 1}],
|
|
4544
|
+
['ShowColumns', {databaseid: 1}],
|
|
4545
|
+
['ShowIndex', {databaseid: 1}],
|
|
4546
|
+
['ShowCreateTable', {databaseid: 1}],
|
|
4547
|
+
['AlterTable', {renameto: 1, renamecolumn: 1, dropcolumn: 1}],
|
|
4548
|
+
];
|
|
4549
|
+
var freeChild = [
|
|
4550
|
+
['CreateTable', {table: 1}],
|
|
4551
|
+
['DropTable', {tables: 1}],
|
|
4552
|
+
['TruncateTable', {table: 1}],
|
|
4553
|
+
['AlterTable', {table: 1}],
|
|
4554
|
+
['ShowColumns', {table: 1}],
|
|
4555
|
+
['ShowIndex', {table: 1}],
|
|
4556
|
+
['ShowCreateTable', {table: 1}],
|
|
4557
|
+
['CreateIndex', {table: 1}],
|
|
4558
|
+
['CreateTrigger', {table: 1}],
|
|
4559
|
+
['Declare', {declares: 1}],
|
|
4560
|
+
];
|
|
4561
|
+
var skipChild = [['Select', {pivot: 1, unpivot: 1}]];
|
|
4562
|
+
|
|
4563
|
+
function freeOf(list, node) {
|
|
4564
|
+
var yy = alasql.yy;
|
|
4565
|
+
for (var i = 0; i < list.length; i++) {
|
|
4566
|
+
var cls = yy[list[i][0]];
|
|
4567
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
4568
|
+
}
|
|
4569
|
+
return null;
|
|
4570
|
+
}
|
|
4571
|
+
|
|
4572
|
+
// An @variable: an expression pastes it escaped where varValueFree is true, FROM @x pastes it
|
|
4573
|
+
// raw, and SELECT INTO @x pastes it raw where intoVarFree is false.
|
|
4574
|
+
function freeVar(node, key, entry) {
|
|
4575
|
+
var yy = alasql.yy;
|
|
4576
|
+
if (key !== 'variable' || !(node instanceof yy.VarValue)) return false;
|
|
4577
|
+
if (entry === 'source') return false;
|
|
4578
|
+
if (entry === 'into') return intoVarFree;
|
|
4579
|
+
return varValueFree;
|
|
4580
|
+
}
|
|
4581
|
+
|
|
4582
|
+
// SET @x = value without a path is a run-time assignment; with a path the name is pasted
|
|
4583
|
+
function freeSet(node, key) {
|
|
4584
|
+
var yy = alasql.yy;
|
|
4585
|
+
return key === 'variable' && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4588
|
+
// data is true inside a JSON value, where a plain object is data and only a node is looked at.
|
|
4589
|
+
// entry is what entryOf says about the node as an entry of its parent, or 'free' when its own
|
|
4590
|
+
// names never reach generated code.
|
|
4591
|
+
function checkNames(node, data, entry) {
|
|
4592
|
+
if (node === null || typeof node !== 'object') return;
|
|
4593
|
+
var i;
|
|
4594
|
+
if (Array.isArray(node)) {
|
|
4595
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
4596
|
+
return;
|
|
4597
|
+
}
|
|
4598
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
4599
|
+
if (data && !isNode) {
|
|
4600
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
4601
|
+
return;
|
|
4602
|
+
}
|
|
4603
|
+
var yy = alasql.yy;
|
|
4604
|
+
if (node instanceof yy.Json) {
|
|
4605
|
+
checkNames(node.value, true, false);
|
|
4606
|
+
return;
|
|
4607
|
+
}
|
|
4608
|
+
var fk = freeOf(freeKeys, node);
|
|
4609
|
+
var fc = freeOf(freeChild, node);
|
|
4610
|
+
var sc = freeOf(skipChild, node);
|
|
4611
|
+
for (var key in node) {
|
|
4612
|
+
if (!hasOwn.call(node, key)) continue;
|
|
4613
|
+
var value = node[key];
|
|
4614
|
+
if (sc && sc[key] === 1) continue;
|
|
4615
|
+
if (key === 'order' && node instanceof yy.Select && Array.isArray(value)) {
|
|
4616
|
+
checkOrder(node.columns, value);
|
|
4617
|
+
continue;
|
|
4618
|
+
}
|
|
4619
|
+
// the column list of a WITH entry renames the result at run time
|
|
4620
|
+
var child = (fc && fc[key] === 1) || (entry === 'with' && key === 'columns') ? 'free' : '';
|
|
4621
|
+
if (!child && node instanceof yy.Select) child = key === 'from' ? 'source' : key === 'into' ? 'into' : '';
|
|
4622
|
+
if (typeof value === 'string') {
|
|
4623
|
+
if (entry === 'free' || (fk && fk[key] === 1) || freeSet(node, key) || freeVar(node, key, entry))
|
|
4624
|
+
continue;
|
|
4625
|
+
if (key === 'name' ? entry === 'with' : nameKeys[key] === 1 && !(entry === 'alias' && key === 'as'))
|
|
4626
|
+
checkName(value);
|
|
4627
|
+
} else if (value !== null && typeof value === 'object') {
|
|
4628
|
+
if (Array.isArray(value)) {
|
|
4629
|
+
for (i = 0; i < value.length; i++) {
|
|
4630
|
+
if (typeof value[i] === 'string') {
|
|
4631
|
+
if (nameListKeys[key] === 1 && entry !== 'free' && child !== 'free') checkName(value[i]);
|
|
4632
|
+
} else {
|
|
4633
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
} else {
|
|
4637
|
+
checkNames(value, false, child);
|
|
4638
|
+
}
|
|
4639
|
+
}
|
|
4640
|
+
}
|
|
4641
|
+
}
|
|
4642
|
+
|
|
4643
|
+
return function (ast) {
|
|
4644
|
+
checkNames(ast, false, false);
|
|
4645
|
+
};
|
|
4646
|
+
})();
|
|
4647
|
+
|
|
4456
4648
|
/**
|
|
4457
4649
|
List of engines of external databases
|
|
4458
4650
|
@type {object}
|
|
@@ -6947,7 +7139,7 @@ function queryfn3(query) {
|
|
|
6947
7139
|
|
|
6948
7140
|
// Prepare variables
|
|
6949
7141
|
query.data = [];
|
|
6950
|
-
query.xgroups
|
|
7142
|
+
query.xgroups=Object.create(null);
|
|
6951
7143
|
query.groups = [];
|
|
6952
7144
|
|
|
6953
7145
|
// Level of Joins
|
|
@@ -7988,7 +8180,7 @@ yy.Select.prototype.compile = function (databaseid, params) {
|
|
|
7988
8180
|
// Save data into parameters array
|
|
7989
8181
|
// like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
|
|
7990
8182
|
//
|
|
7991
|
-
query.intofns = "params['" + this.into.param + "'].push(r)";
|
|
8183
|
+
query.intofns = "params['" + escapeq(this.into.param) + "'].push(r)";
|
|
7992
8184
|
}
|
|
7993
8185
|
|
|
7994
8186
|
if (query.intofns) {
|
|
@@ -8393,7 +8585,7 @@ yy.Select.prototype.compileFrom = function (query) {
|
|
|
8393
8585
|
return res;
|
|
8394
8586
|
};
|
|
8395
8587
|
} else if (tq instanceof yy.ParamValue) {
|
|
8396
|
-
ps = "var res = alasql.prepareFromData(params['" + tq.param + "']";
|
|
8588
|
+
ps = "var res = alasql.prepareFromData(params['" + escapeq(tq.param) + "']";
|
|
8397
8589
|
|
|
8398
8590
|
if (tq.array) ps += ',true';
|
|
8399
8591
|
ps += ');if(cb)res=cb(res,idx,query);return res';
|
|
@@ -8642,7 +8834,7 @@ yy.Select.prototype.compileJoins = function (query) {
|
|
|
8642
8834
|
// source.data = ;
|
|
8643
8835
|
var jnparam = jn.param.param;
|
|
8644
8836
|
|
|
8645
|
-
ps = "var res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
8837
|
+
ps = "var res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
8646
8838
|
if (jn.array) ps += ',true';
|
|
8647
8839
|
ps += ');if(cb)res=cb(res, idx, query);return res';
|
|
8648
8840
|
|
|
@@ -9341,9 +9533,10 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9341
9533
|
|
|
9342
9534
|
if (columns && columns.length > 0) {
|
|
9343
9535
|
columns.forEach(function (tcol) {
|
|
9536
|
+
var escapedColumnId = escapeq(tcol.columnid);
|
|
9344
9537
|
if (joinstar && alasql.options.joinstar == 'underscore') {
|
|
9345
9538
|
ss.push(
|
|
9346
|
-
"'" + alias + '_' +
|
|
9539
|
+
"'" + alias + '_' + escapedColumnId + "':p['" + alias + "']['" + escapedColumnId + "']"
|
|
9347
9540
|
);
|
|
9348
9541
|
} else if (joinstar && alasql.options.joinstar == 'json') {
|
|
9349
9542
|
// ss.push('\''+alias+'_'+tcol.columnid+'\':p[\''+alias+'\'][\''+tcol.columnid+'\']');
|
|
@@ -9351,16 +9544,16 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9351
9544
|
"r['" +
|
|
9352
9545
|
alias +
|
|
9353
9546
|
"']['" +
|
|
9354
|
-
|
|
9547
|
+
escapedColumnId +
|
|
9355
9548
|
"']=p['" +
|
|
9356
9549
|
alias +
|
|
9357
9550
|
"']['" +
|
|
9358
|
-
|
|
9551
|
+
escapedColumnId +
|
|
9359
9552
|
"'];";
|
|
9360
9553
|
} else {
|
|
9361
|
-
var value = "p['" + alias + "']['" +
|
|
9554
|
+
var value = "p['" + alias + "']['" + escapedColumnId + "']";
|
|
9362
9555
|
if (!columnIds[tcol.columnid]) {
|
|
9363
|
-
var key = "'" +
|
|
9556
|
+
var key = "'" + escapedColumnId + "':";
|
|
9364
9557
|
ss.push(key + value);
|
|
9365
9558
|
columnIds[tcol.columnid] = {
|
|
9366
9559
|
id: ss.length - 1,
|
|
@@ -9391,7 +9584,7 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9391
9584
|
} else {
|
|
9392
9585
|
|
|
9393
9586
|
// if column not exist, then copy all
|
|
9394
|
-
sp += 'var w=p["' + alias + '"];for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
|
|
9587
|
+
sp += 'var w=p["' + escapeq(alias) + '"];for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
|
|
9395
9588
|
|
|
9396
9589
|
query.dirtyColumns = true;
|
|
9397
9590
|
}
|
|
@@ -9418,7 +9611,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9418
9611
|
if (col.columnid === '*') {
|
|
9419
9612
|
if (col.func) {
|
|
9420
9613
|
sp +=
|
|
9421
|
-
"r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9614
|
+
"r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9422
9615
|
} else if (col.tableid) {
|
|
9423
9616
|
//Copy all
|
|
9424
9617
|
var ret = compileSelectStar(query, [col.tableid], false);
|
|
@@ -9470,7 +9663,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9470
9663
|
if (isMultisheetParam) {
|
|
9471
9664
|
sp =
|
|
9472
9665
|
'var r={};var w=p["' +
|
|
9473
|
-
tbid +
|
|
9666
|
+
escapeq(tbid) +
|
|
9474
9667
|
'"];' +
|
|
9475
9668
|
'var cols=[' +
|
|
9476
9669
|
self.columns
|
|
@@ -9481,7 +9674,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9481
9674
|
'];var colas=[' +
|
|
9482
9675
|
self.columns
|
|
9483
9676
|
.map(function (col) {
|
|
9484
|
-
return "'" + (col.as || col.columnid) + "'";
|
|
9677
|
+
return "'" + escapeq(col.as || col.columnid) + "'";
|
|
9485
9678
|
})
|
|
9486
9679
|
.join(',') +
|
|
9487
9680
|
'];' +
|
|
@@ -9644,9 +9837,9 @@ yy.Select.prototype.compileSelect2 = function (query, params) {
|
|
|
9644
9837
|
this.orderColumns.forEach(function (v, idx) {
|
|
9645
9838
|
var key = '$$$' + idx;
|
|
9646
9839
|
if (v instanceof yy.Column && query.xcolumns[v.columnid]) {
|
|
9647
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9840
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9648
9841
|
} else if (v instanceof yy.ParamValue && query.xcolumns[params[v.param]]) {
|
|
9649
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
9842
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
9650
9843
|
} else {
|
|
9651
9844
|
s += "r['" + key + "']=" + v.toJS('p', query.defaultTableid, query.defcols) + ';';
|
|
9652
9845
|
}
|
|
@@ -9739,7 +9932,7 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
|
|
|
9739
9932
|
query.groupColumns[colas] = col.nick;
|
|
9740
9933
|
|
|
9741
9934
|
// if(col.as) {
|
|
9742
|
-
s += "r['" + colas + "']=";
|
|
9935
|
+
s += "r['" + (col.as !== undefined ? escapeq(colas) : colas) + "']=";
|
|
9743
9936
|
// // } else {
|
|
9744
9937
|
// // s += 'r[\''+escapeq()+'\']=';
|
|
9745
9938
|
// // };
|
|
@@ -9766,7 +9959,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9766
9959
|
self.columns.forEach(function (col) {
|
|
9767
9960
|
|
|
9768
9961
|
if (query.ingroup.indexOf(col.nick) > -1) {
|
|
9769
|
-
s += "r['" + (col.as
|
|
9962
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + col.nick + "'];";
|
|
9770
9963
|
}
|
|
9771
9964
|
});
|
|
9772
9965
|
|
|
@@ -9776,7 +9969,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9776
9969
|
var key = '$$$' + idx;
|
|
9777
9970
|
|
|
9778
9971
|
if (v instanceof yy.Column && query.groupColumns[v.columnid]) {
|
|
9779
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9972
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9780
9973
|
} else {
|
|
9781
9974
|
s += "r['" + key + "']=" + v.toJS('g', '') + ';';
|
|
9782
9975
|
}
|
|
@@ -10844,7 +11037,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10844
11037
|
var ljs = '(' + leftJS() + '||{})';
|
|
10845
11038
|
|
|
10846
11039
|
if (typeof this.right === 'string') {
|
|
10847
|
-
s = ljs + '["' + this.right + '"]';
|
|
11040
|
+
s = ljs + '["' + escapeq(this.right) + '"]';
|
|
10848
11041
|
} else if (typeof this.right === 'number') {
|
|
10849
11042
|
s = ljs + '[' + this.right + ']';
|
|
10850
11043
|
} else if (this.right instanceof yy.FuncValue) {
|
|
@@ -10860,7 +11053,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10860
11053
|
|
|
10861
11054
|
if (this.op === '!') {
|
|
10862
11055
|
if (typeof this.right === 'string') {
|
|
10863
|
-
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + this.right + '"]';
|
|
11056
|
+
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + escapeq(this.right) + '"]';
|
|
10864
11057
|
}
|
|
10865
11058
|
// TODO - add other cases
|
|
10866
11059
|
}
|
|
@@ -11186,7 +11379,7 @@ yy.ParamValue.prototype.toString = function () {
|
|
|
11186
11379
|
};
|
|
11187
11380
|
yy.ParamValue.prototype.toJS = function () {
|
|
11188
11381
|
if (typeof this.param === 'string') {
|
|
11189
|
-
return "params['" + this.param + "']";
|
|
11382
|
+
return "params['" + escapeq(this.param) + "']";
|
|
11190
11383
|
}
|
|
11191
11384
|
|
|
11192
11385
|
return 'params[' + this.param + ']';
|
|
@@ -12248,9 +12441,23 @@ var JSONtoString = (alasql.utils.JSONtoString = function (obj) {
|
|
|
12248
12441
|
return s;
|
|
12249
12442
|
});
|
|
12250
12443
|
|
|
12444
|
+
// A string value or key of a JSON value goes between double quotes in the generated code. A
|
|
12445
|
+
// backslash pair keeps its meaning; a lone backslash at the end, a double quote and a line break
|
|
12446
|
+
// are escaped, so the string cannot end early.
|
|
12447
|
+
function escapeJSONString(s) {
|
|
12448
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function (c) {
|
|
12449
|
+
if (c.length === 2) return c;
|
|
12450
|
+
if (c === '\\') return '\\\\';
|
|
12451
|
+
if (c === '"') return '\\"';
|
|
12452
|
+
if (c === '\n') return '\\n';
|
|
12453
|
+
if (c === '\r') return '\\r';
|
|
12454
|
+
return c === '\u2028' ? '\\u2028' : '\\u2029';
|
|
12455
|
+
});
|
|
12456
|
+
}
|
|
12457
|
+
|
|
12251
12458
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
12252
12459
|
var s = '';
|
|
12253
|
-
if (typeof obj == 'string') s = '"' + obj + '"';
|
|
12460
|
+
if (typeof obj == 'string') s = '"' + escapeJSONString(obj) + '"';
|
|
12254
12461
|
else if (typeof obj == 'number') s = '(' + obj + ')';
|
|
12255
12462
|
else if (typeof obj == 'boolean') s = obj;
|
|
12256
12463
|
else if (typeof obj == 'object') {
|
|
@@ -12269,7 +12476,7 @@ function JSONtoJS(obj, context, tableid, defcols) {
|
|
|
12269
12476
|
var ss = [];
|
|
12270
12477
|
for (var k in obj) {
|
|
12271
12478
|
var s1 = '';
|
|
12272
|
-
if (typeof k == 'string') s1 += '"' + k + '"';
|
|
12479
|
+
if (typeof k == 'string') s1 += '"' + escapeJSONString(k) + '"';
|
|
12273
12480
|
else if (typeof k == 'number') s1 += k;
|
|
12274
12481
|
else if (typeof k == 'boolean') s1 += k;
|
|
12275
12482
|
else {
|
|
@@ -15665,19 +15872,19 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
|
|
|
15665
15872
|
}
|
|
15666
15873
|
if (this.props && this.props.length > 0) {
|
|
15667
15874
|
if (this.method == '@') {
|
|
15668
|
-
var fs = "alasql.vars['"
|
|
15875
|
+
var fs = "alasql.vars[k('"+this.variable+"')]";
|
|
15669
15876
|
} else {
|
|
15670
|
-
var fs = "params['"
|
|
15877
|
+
var fs = "params[k('"+this.variable+"')]";
|
|
15671
15878
|
}
|
|
15672
15879
|
fs += this.props
|
|
15673
15880
|
.map(function (prop) {
|
|
15674
15881
|
if (typeof prop == 'string') {
|
|
15675
|
-
return "['"
|
|
15882
|
+
return "[k('"+prop+"')]";
|
|
15676
15883
|
} else if (typeof prop == 'number') {
|
|
15677
15884
|
return '[' + prop + ']';
|
|
15678
15885
|
} else {
|
|
15679
15886
|
|
|
15680
|
-
return
|
|
15887
|
+
return "[k("+prop.toJS()+")]";
|
|
15681
15888
|
// } else {
|
|
15682
15889
|
|
|
15683
15890
|
// throw new Error('Wrong SET property');
|
|
@@ -15685,7 +15892,7 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
|
|
|
15685
15892
|
})
|
|
15686
15893
|
.join();
|
|
15687
15894
|
|
|
15688
|
-
new Function('value,params,alasql', 'var y;
|
|
15895
|
+
new Function('value,params,alasql', 'var y;var k=function(x){if(x==="__proto__"||x==="constructor"||x==="prototype")throw new Error(x+" is not allowed");return x};'+fs+'=value')(res, params, alasql);
|
|
15689
15896
|
} else {
|
|
15690
15897
|
if (this.method == '@') {
|
|
15691
15898
|
alasql.vars[this.variable] = res;
|