Skip to content

Commit bf140a6

Browse files
prx-lmomportuga
authored andcommitted
advanced security
removed object reference removed row copy [hotfix/7187] - now moved to own finding function - value gets pushed to an array and extracted from there changed array literal set self variable declared function lint error corrected columnDefs call
1 parent 0b665b1 commit bf140a6

File tree

1 file changed

+25
-42
lines changed
  • packages/core/src/js/factories

1 file changed

+25
-42
lines changed

packages/core/src/js/factories/Grid.js

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -686,21 +686,9 @@ angular.module('ui.grid')
686686
* @param {string} name column name
687687
*/
688688
Grid.prototype.getColumn = function getColumn(name) {
689-
if (this.columns && angular.isFunction(this.columns.find)) {
690-
return this.columns.find(function (column) {
691-
return column.colDef.name === name;
692-
}) || null;
693-
}
694-
695-
var result = null;
696-
this.columns.every(function (column) {
697-
if ( column.colDef.name === name ) {
698-
result = column;
699-
return false;
700-
}
701-
return true;
689+
return arrayFinder(this.columns, function (column) {
690+
return column.colDef.name === name;
702691
});
703-
return result;
704692
};
705693

706694
/**
@@ -711,21 +699,9 @@ angular.module('ui.grid')
711699
* @param {string} name column.field
712700
*/
713701
Grid.prototype.getColDef = function getColDef(name) {
714-
if (this.options.columnsDefs && angular.isFunction(this.options.columnsDefs.find)) {
715-
return this.options.columnsDefs.find(function (colDef) {
716-
return colDef.name === name;
717-
}) || null;
718-
}
719-
720-
var result = null;
721-
this.options.columnsDefs.every(function (colDef) {
722-
if ( colDef.name === name ) {
723-
result = colDef;
724-
return false;
725-
}
726-
return true;
702+
return arrayFinder(this.options.columnDefs, function (colDef) {
703+
return colDef.name === name;
727704
});
728-
return result;
729705
};
730706

731707
/**
@@ -1094,6 +1070,25 @@ angular.module('ui.grid')
10941070
return t;
10951071
};
10961072

1073+
var arrayFinder = function(array, func) {
1074+
if (array && array.length) {
1075+
var arr = [];
1076+
if (angular.isFunction(array.find)) {
1077+
return arr.push(array.find(func))[0] || null;
1078+
}
1079+
1080+
array.every(function (entry) {
1081+
if ( func(entry) ) {
1082+
arr.push(entry);
1083+
return false;
1084+
}
1085+
return true;
1086+
});
1087+
return arr.length ? arr[0] : null;
1088+
}
1089+
return null;
1090+
}
1091+
10971092
/**
10981093
* @ngdoc function
10991094
* @name getRow
@@ -1106,21 +1101,9 @@ angular.module('ui.grid')
11061101
Grid.prototype.getRow = function getRow(rowEntity, lookInRows) {
11071102
var self = this;
11081103
lookInRows = lookInRows == void 0 ? this.rows : lookInRows;
1109-
if (lookInRows && angular.isFunction(lookInRows.find)) {
1110-
return lookInRows.find(function (row) {
1111-
return self.options.rowEquality(row.entity, rowEntity);
1112-
}) || null;
1113-
}
1114-
1115-
var result = null;
1116-
lookInRows.every(function (row) {
1117-
if ( self.options.rowEquality(row.entity, rowEntity) ) {
1118-
result = row;
1119-
return false;
1120-
}
1121-
return true;
1104+
return arrayFinder(lookInRows, function (row) {
1105+
return self.options.rowEquality(row.entity, rowEntity);
11221106
});
1123-
return result;
11241107
};
11251108

11261109

0 commit comments

Comments
 (0)