Skip to content

Commit 63346ee

Browse files
authored
Merge pull request #283 from devpaul/grid-cleanup
Cleans up a grid issue making editing rows more secure
2 parents 72db30b + e92ee87 commit 63346ee

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

grid/_Builder.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,28 +260,31 @@ define([
260260

261261
// time critical: generate html using cache and data source
262262
generateHtml: function(inDataIndex, inRowIndex){
263-
var
264-
html = this.getTableArray(),
265-
v = this.view, dir,
266-
cells = v.structure.cells,
267-
item = this.grid.getItem(inRowIndex);
263+
var html = this.getTableArray();
264+
var v = this.view;
265+
var cells = v.structure.cells;
266+
var item = this.grid.getItem(inRowIndex);
267+
var dir;
268268

269269
util.fire(this.view, "onBeforeRow", [inRowIndex, cells]);
270-
for(var j=0, row; (row=cells[j]); j++){
270+
for(var j=0, row; (row = cells[j]); j++){
271271
if(row.hidden || row.header){
272272
continue;
273273
}
274274
html.push(!row.invisible ? '<tr>' : '<tr class="dojoxGridInvisible">');
275275
for(var i=0, cell, m, cc, cs; (cell=row[i]); i++){
276-
m = cell.markup; cc = cell.customClasses = []; cs = cell.customStyles = [];
276+
m = cell.markup;
277+
cc = cell.customClasses = [];
278+
cs = cell.customStyles = [];
279+
277280
// content (format can fill in cc and cs as side-effects)
278281
m[5] = cell.format(inRowIndex, item);
279282
// classes
280283
m[1] = cc.join(' ');
281284
// styles
282285
m[3] = cs.join(';');
283286
dir = cell.textDir || this.grid.textDir;
284-
if(dir){
287+
if (dir) {
285288
m[3] += this._getTextDirStyle(dir, cell, inRowIndex);
286289
}
287290
// in-place concat

grid/cells/_base.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ define([
102102
// grid row index
103103
// returns:
104104
// html for a given grid cell
105-
var f, i=this.grid.edit.info, d=this.get ? this.get(inRowIndex, inItem) : (this.value || this.defaultValue);
106-
d = (d && d.replace && this.grid.escapeHTMLInData) ? d.replace(/&/g, '&amp;').replace(/</g, '&lt;') : d;
107-
if(this.editable && (this.alwaysEditing || (i.rowIndex==inRowIndex && i.cell==this))){
105+
var i = this.grid.edit.info;
106+
var d = this.get ? this.get(inRowIndex, inItem) : (this.value || this.defaultValue);
107+
if (d && d.replace && this.grid.escapeHTMLInData) {
108+
d = d.replace(/&/g, '&amp;').replace(/</g, '&lt;');
109+
}
110+
if (this.editable && (this.alwaysEditing || (i.rowIndex==inRowIndex && i.cell==this))){
108111
return this.formatEditing(i.value ? i.value : d, inRowIndex);
109-
}else{
112+
} else {
110113
return this._defaultFormat(d, [d, inRowIndex, this]);
111114
}
112115
},
@@ -329,6 +332,10 @@ define([
329332
keyFilter: null,
330333
formatEditing: function(inDatum, inRowIndex){
331334
this.needFormatNode(inDatum, inRowIndex);
335+
if (inDatum && inDatum.replace) {
336+
// escape quotes to avoid XSS
337+
inDatum = inDatum.replace(/"/g, '&quot;')
338+
}
332339
return '<input class="dojoxGridInput" type="text" value="' + inDatum + '">';
333340
},
334341
formatNode: function(inNode, inDatum, inRowIndex){
@@ -478,4 +485,4 @@ define([
478485

479486
return BaseCell;
480487

481-
});
488+
});

0 commit comments

Comments
 (0)