alasql 4.3.3 → 4.3.5

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  //
4
4
  // Command line interface for Alasql
5
- // Version: 0.2.3
5
+ // Version: 4.3.5
6
6
  // Date: 28.07.2015
7
7
  // (c) 2014-2022, Andrey Gershun & Mathias Wulff
8
8
  //
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.3.2 build: develop-6ecba2e1 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.3.5 build: develop-6ecba2e1 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.3.2
4
+ @version 4.3.5
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2024 Andrey Gershun & Mathias Wulff
package/dist/alasql.fs.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.3.2 build: develop-6ecba2e1 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.3.5 build: develop-6ecba2e1 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.3.2
4
+ @version 4.3.5
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2024 Andrey Gershun & Mathias Wulff
@@ -141,7 +141,7 @@ SOFTWARE.
141
141
  Current version of alasql
142
142
  @constant {string}
143
143
  */
144
- alasql.version = '4.3.2';
144
+ alasql.version = '4.3.5';
145
145
  alasql.build = 'develop-6ecba2e1';
146
146
 
147
147
  /**
@@ -2497,7 +2497,7 @@ next:function () {
2497
2497
 
2498
2498
  // return next match that has a token
2499
2499
  lex:function lex () {
2500
- var r = this.next();
2500
+ var r = this.next();if(r&&/^(N?['"]__proto__['"]|\[__proto__\]|`__proto__`|__proto__)$/i.test(this.yytext))throw new Error("__proto__ is not allowed");
2501
2501
  if (r) {
2502
2502
  return r;
2503
2503
  } else {
@@ -4039,11 +4039,11 @@ var cloneDeep = (utils.cloneDeep = function cloneDeep(obj) {
4039
4039
  return +obj;
4040
4040
  }
4041
4041
 
4042
- var temp = new obj.constructor(); // changed
4042
+ var temp = new (Object.prototype.hasOwnProperty.call(obj, 'constructor') ? Object : obj.constructor)(); // changed
4043
4043
 
4044
4044
  for (var key in obj) {
4045
4045
  if (obj.hasOwnProperty(key)) {
4046
- temp[key] = cloneDeep(obj[key]);
4046
+ /* A "__proto__" key from parsed data is copied as data, never as the prototype */ if (key === '__proto__') { Object.defineProperty(temp, key, {value: cloneDeep(obj[key]), writable: true, enumerable: true, configurable: true}); } else { temp[key] = cloneDeep(obj[key]); }
4047
4047
  }
4048
4048
  }
4049
4049
  return temp;
@@ -4115,7 +4115,7 @@ var extend = (utils.extend = function extend(a, b) {
4115
4115
  a = a || {};
4116
4116
  for (var key in b) {
4117
4117
  if (b.hasOwnProperty(key)) {
4118
- a[key] = b[key];
4118
+ /* A "__proto__" key from parsed data is copied as data, never as the prototype */ if (key === '__proto__') { Object.defineProperty(a, key, {value: b[key], writable: true, enumerable: true, configurable: true}); } else { a[key] = b[key]; }
4119
4119
  }
4120
4120
  }
4121
4121
  return a;
@@ -6533,7 +6533,7 @@ function queryfn3(query) {
6533
6533
 
6534
6534
  // Prepare variables
6535
6535
  query.data = [];
6536
- query.xgroups = {};
6536
+ query.xgroups=Object.create(null);
6537
6537
  query.groups = [];
6538
6538
 
6539
6539
  // Level of Joins
@@ -8369,7 +8369,7 @@ yy.Select.prototype.compileGroup = function (query) {
8369
8369
  aft2 = '';
8370
8370
 
8371
8371
  if (typeof query.groupStar !== 'undefined') {
8372
- aft2 += "for(var f in p['" + query.groupStar + "']) {g[f]=p['" + query.groupStar + "'][f];};";
8372
+ aft2 += "for(var f in p['" + query.groupStar + "']) {if(/^__proto__$/.test(f))Object.defineProperty(g,f,{writable:true,enumerable:true,configurable:true});g[f]=p['" + query.groupStar + "'][f];};";
8373
8373
  }
8374
8374
 
8375
8375
  s += query.selectGroup
@@ -8705,7 +8705,7 @@ function compileSelectStar(query, aliases, joinstar) {
8705
8705
  } else {
8706
8706
 
8707
8707
  // if column not exist, then copy all
8708
- sp += 'var w=p["' + alias + '"];for(var k in w){r[k]=w[k]};';
8708
+ 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]};';
8709
8709
 
8710
8710
  query.dirtyColumns = true;
8711
8711
  }
@@ -9033,10 +9033,10 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
9033
9033
  self.columns.forEach(function (col) {
9034
9034
 
9035
9035
  if (col instanceof yy.Column && col.columnid === '*') {
9036
- // s += 'for(var k in g){r[k]=g[k]};';
9036
+ // s += 'for(var k in g){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=g[k]};';
9037
9037
  // s += 'for(var k in this.query.groupColumns){r[k]=g[this.query.groupColumns[k]]};';
9038
9038
 
9039
- s += 'for(var k in g) {r[k]=g[k]};';
9039
+ s += 'for(var k in g) {if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=g[k]};';
9040
9040
  return '';
9041
9041
 
9042
9042
  } else {
@@ -10143,7 +10143,7 @@ yy.Over = class Over {
10143
10143
  const allValues = this.right.map(value => value.value);
10144
10144
  const allValuesStr = allValues.join(',');
10145
10145
  alasql.sets[allValuesStr] = alasql.sets[allValuesStr] || new Set(allValues);
10146
- s = `alasql.sets["${allValuesStr}"].has(alasql.utils.getValueOf(${leftJS()}))`;
10146
+ s = `alasql.sets[${JSON.stringify(allValuesStr)}].has(alasql.utils.getValueOf(${leftJS()}))`;
10147
10147
  }
10148
10148
  } else {
10149
10149
  s = `(${rightJS()}.indexOf(${leftJS()}) > -1)`;
@@ -10161,7 +10161,7 @@ yy.Over = class Over {
10161
10161
  const allValues = this.right.map(value => value.value);
10162
10162
  const allValuesStr = allValues.join(',');
10163
10163
  alasql.sets[allValuesStr] = alasql.sets[allValuesStr] || new Set(allValues);
10164
- s = `!alasql.sets["${allValuesStr}"].has(alasql.utils.getValueOf(${leftJS()}))`;
10164
+ s = `!alasql.sets[${JSON.stringify(allValuesStr)}].has(alasql.utils.getValueOf(${leftJS()}))`;
10165
10165
  }
10166
10166
  } else {
10167
10167
  s = `(${rightJS()}.indexOf(${leftJS()}) === -1)`;
@@ -12015,7 +12015,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12015
12015
 
12016
12016
  table.update(
12017
12017
  function (t) {
12018
- for (var f in r) t[f] = r[f];
12018
+ for (var f in r) {if(/^__proto__$/.test(f))Object.defineProperty(t,f,{writable:true,enumerable:true,configurable:true});t[f] = r[f];}
12019
12019
  },
12020
12020
  table.data.indexOf(toreplace),
12021
12021
  params
@@ -13510,7 +13510,7 @@ yy.Insert.prototype.compile = function (databaseid) {
13510
13510
  });
13511
13511
  } else {
13512
13512
 
13513
- // sw = 'var w='+JSONtoJS(values)+';for(var k in w){r[k]=w[k]};';
13513
+ // sw = 'var w='+JSONtoJS(values)+';for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
13514
13514
  sw = JSONtoJS(values);
13515
13515
  }
13516
13516
  }
@@ -14542,22 +14542,22 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
14542
14542
  if (this.props && this.props.length > 0) {
14543
14543
  let fs;
14544
14544
  if (this.method === '@') {
14545
- fs = `alasql.vars['${this.variable}']`;
14545
+ fs = `alasql.vars[k('${this.variable}')]`;
14546
14546
  } else {
14547
- fs = `params['${this.variable}']`;
14547
+ fs = `params[k('${this.variable}')]`;
14548
14548
  }
14549
14549
  this.props.forEach(prop => {
14550
14550
  if (typeof prop === 'string') {
14551
- fs += `['${prop}']`;
14551
+ fs += `[k('${prop}')]`;
14552
14552
  } else if (typeof prop === 'number') {
14553
14553
  fs += `[${prop}]`;
14554
14554
  } else {
14555
14555
  // Assuming prop.toJS() is a method that converts prop to a JavaScript expression.
14556
- fs += `[${prop.toJS()}]`;
14556
+ fs += `[k(${prop.toJS()})]`;
14557
14557
  }
14558
14558
  });
14559
14559
 
14560
- new Function('value, params, alasql', `${fs} = value`)(res, params, alasql);
14560
+ new Function('value, params, alasql', `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);
14561
14561
  } else {
14562
14562
  if (this.method === '@') {
14563
14563
  alasql.vars[this.variable] = res;
package/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.3.2 build: develop-6ecba2e1 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.3.5 build: develop-6ecba2e1 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.3.2
4
+ @version 4.3.5
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2024 Andrey Gershun & Mathias Wulff
@@ -141,7 +141,7 @@ SOFTWARE.
141
141
  Current version of alasql
142
142
  @constant {string}
143
143
  */
144
- alasql.version = '4.3.2';
144
+ alasql.version = '4.3.5';
145
145
  alasql.build = 'develop-6ecba2e1';
146
146
 
147
147
  /**
@@ -2497,7 +2497,7 @@ next:function () {
2497
2497
 
2498
2498
  // return next match that has a token
2499
2499
  lex:function lex () {
2500
- var r = this.next();
2500
+ var r = this.next();if(r&&/^(N?['"]__proto__['"]|\[__proto__\]|`__proto__`|__proto__)$/i.test(this.yytext))throw new Error("__proto__ is not allowed");
2501
2501
  if (r) {
2502
2502
  return r;
2503
2503
  } else {
@@ -4039,11 +4039,11 @@ var cloneDeep = (utils.cloneDeep = function cloneDeep(obj) {
4039
4039
  return +obj;
4040
4040
  }
4041
4041
 
4042
- var temp = new obj.constructor(); // changed
4042
+ var temp = new (Object.prototype.hasOwnProperty.call(obj, 'constructor') ? Object : obj.constructor)(); // changed
4043
4043
 
4044
4044
  for (var key in obj) {
4045
4045
  if (obj.hasOwnProperty(key)) {
4046
- temp[key] = cloneDeep(obj[key]);
4046
+ /* A "__proto__" key from parsed data is copied as data, never as the prototype */ if (key === '__proto__') { Object.defineProperty(temp, key, {value: cloneDeep(obj[key]), writable: true, enumerable: true, configurable: true}); } else { temp[key] = cloneDeep(obj[key]); }
4047
4047
  }
4048
4048
  }
4049
4049
  return temp;
@@ -4115,7 +4115,7 @@ var extend = (utils.extend = function extend(a, b) {
4115
4115
  a = a || {};
4116
4116
  for (var key in b) {
4117
4117
  if (b.hasOwnProperty(key)) {
4118
- a[key] = b[key];
4118
+ /* A "__proto__" key from parsed data is copied as data, never as the prototype */ if (key === '__proto__') { Object.defineProperty(a, key, {value: b[key], writable: true, enumerable: true, configurable: true}); } else { a[key] = b[key]; }
4119
4119
  }
4120
4120
  }
4121
4121
  return a;
@@ -6533,7 +6533,7 @@ function queryfn3(query) {
6533
6533
 
6534
6534
  // Prepare variables
6535
6535
  query.data = [];
6536
- query.xgroups = {};
6536
+ query.xgroups=Object.create(null);
6537
6537
  query.groups = [];
6538
6538
 
6539
6539
  // Level of Joins
@@ -8369,7 +8369,7 @@ yy.Select.prototype.compileGroup = function (query) {
8369
8369
  aft2 = '';
8370
8370
 
8371
8371
  if (typeof query.groupStar !== 'undefined') {
8372
- aft2 += "for(var f in p['" + query.groupStar + "']) {g[f]=p['" + query.groupStar + "'][f];};";
8372
+ aft2 += "for(var f in p['" + query.groupStar + "']) {if(/^__proto__$/.test(f))Object.defineProperty(g,f,{writable:true,enumerable:true,configurable:true});g[f]=p['" + query.groupStar + "'][f];};";
8373
8373
  }
8374
8374
 
8375
8375
  s += query.selectGroup
@@ -8705,7 +8705,7 @@ function compileSelectStar(query, aliases, joinstar) {
8705
8705
  } else {
8706
8706
 
8707
8707
  // if column not exist, then copy all
8708
- sp += 'var w=p["' + alias + '"];for(var k in w){r[k]=w[k]};';
8708
+ 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]};';
8709
8709
 
8710
8710
  query.dirtyColumns = true;
8711
8711
  }
@@ -9033,10 +9033,10 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
9033
9033
  self.columns.forEach(function (col) {
9034
9034
 
9035
9035
  if (col instanceof yy.Column && col.columnid === '*') {
9036
- // s += 'for(var k in g){r[k]=g[k]};';
9036
+ // s += 'for(var k in g){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=g[k]};';
9037
9037
  // s += 'for(var k in this.query.groupColumns){r[k]=g[this.query.groupColumns[k]]};';
9038
9038
 
9039
- s += 'for(var k in g) {r[k]=g[k]};';
9039
+ s += 'for(var k in g) {if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=g[k]};';
9040
9040
  return '';
9041
9041
 
9042
9042
  } else {
@@ -10143,7 +10143,7 @@ yy.Over = class Over {
10143
10143
  const allValues = this.right.map(value => value.value);
10144
10144
  const allValuesStr = allValues.join(',');
10145
10145
  alasql.sets[allValuesStr] = alasql.sets[allValuesStr] || new Set(allValues);
10146
- s = `alasql.sets["${allValuesStr}"].has(alasql.utils.getValueOf(${leftJS()}))`;
10146
+ s = `alasql.sets[${JSON.stringify(allValuesStr)}].has(alasql.utils.getValueOf(${leftJS()}))`;
10147
10147
  }
10148
10148
  } else {
10149
10149
  s = `(${rightJS()}.indexOf(${leftJS()}) > -1)`;
@@ -10161,7 +10161,7 @@ yy.Over = class Over {
10161
10161
  const allValues = this.right.map(value => value.value);
10162
10162
  const allValuesStr = allValues.join(',');
10163
10163
  alasql.sets[allValuesStr] = alasql.sets[allValuesStr] || new Set(allValues);
10164
- s = `!alasql.sets["${allValuesStr}"].has(alasql.utils.getValueOf(${leftJS()}))`;
10164
+ s = `!alasql.sets[${JSON.stringify(allValuesStr)}].has(alasql.utils.getValueOf(${leftJS()}))`;
10165
10165
  }
10166
10166
  } else {
10167
10167
  s = `(${rightJS()}.indexOf(${leftJS()}) === -1)`;
@@ -12015,7 +12015,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12015
12015
 
12016
12016
  table.update(
12017
12017
  function (t) {
12018
- for (var f in r) t[f] = r[f];
12018
+ for (var f in r) {if(/^__proto__$/.test(f))Object.defineProperty(t,f,{writable:true,enumerable:true,configurable:true});t[f] = r[f];}
12019
12019
  },
12020
12020
  table.data.indexOf(toreplace),
12021
12021
  params
@@ -13510,7 +13510,7 @@ yy.Insert.prototype.compile = function (databaseid) {
13510
13510
  });
13511
13511
  } else {
13512
13512
 
13513
- // sw = 'var w='+JSONtoJS(values)+';for(var k in w){r[k]=w[k]};';
13513
+ // sw = 'var w='+JSONtoJS(values)+';for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
13514
13514
  sw = JSONtoJS(values);
13515
13515
  }
13516
13516
  }
@@ -14542,22 +14542,22 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
14542
14542
  if (this.props && this.props.length > 0) {
14543
14543
  let fs;
14544
14544
  if (this.method === '@') {
14545
- fs = `alasql.vars['${this.variable}']`;
14545
+ fs = `alasql.vars[k('${this.variable}')]`;
14546
14546
  } else {
14547
- fs = `params['${this.variable}']`;
14547
+ fs = `params[k('${this.variable}')]`;
14548
14548
  }
14549
14549
  this.props.forEach(prop => {
14550
14550
  if (typeof prop === 'string') {
14551
- fs += `['${prop}']`;
14551
+ fs += `[k('${prop}')]`;
14552
14552
  } else if (typeof prop === 'number') {
14553
14553
  fs += `[${prop}]`;
14554
14554
  } else {
14555
14555
  // Assuming prop.toJS() is a method that converts prop to a JavaScript expression.
14556
- fs += `[${prop.toJS()}]`;
14556
+ fs += `[k(${prop.toJS()})]`;
14557
14557
  }
14558
14558
  });
14559
14559
 
14560
- new Function('value, params, alasql', `${fs} = value`)(res, params, alasql);
14560
+ new Function('value, params, alasql', `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);
14561
14561
  } else {
14562
14562
  if (this.method === '@') {
14563
14563
  alasql.vars[this.variable] = res;