In our application user inputs are saved as is and returned to UI which responsibility is to encode it.
Here's example JSON data returned from server that contains javascript
{"page":1,"total":1,"records":1,"rows":[{"id":"1","cell":["10jcmjn30jjiej8l499p","NO_ALERTS:Ei hälytyksiä","<script>console.log('jep');</script>","Pentti P.","3.4.2012 15:47","Kaupunki","Teiden auraus, KLO","Muu, Moite, Kiitos","Käsittelyssä, Odottaa vastausta","Ei määritetty","Luottamuksellinen","-","0","Kirjattu","x"]}]}
I have used lots of time to make jqGrid work actually very well in our application (thanks for the great piece of software) and addJSONData has been used so I wouldn't change it without need to do it.
To the problem - in formatter
} else if($.fmatter){
is always called. In my javascript knowledge $.fmatter is always true so the last else won't ever be called. Actually it seems that the bug is in jqGrid's Formatter module not in base module.
$.fn.fmatter doesn't do any encoding. In my situation it never goes to
if ($.fn.fmatter[formatType]){
block but it always returns given cellval as is. Maybe that would be the right place to do encoding?
This is what I did to make this work in our application
$.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
// build main options before element iteration
var v=cellval;
opts = $.extend({}, $.jgrid.formatter, opts);
if ($.fn.fmatter[formatType]){
v = $.fn.fmatter[formatType](cellval, opts, rwd, act);
} else {
v = $.jgrid.htmlEncode(cellval);
}
return v;
};