Hello, I have JS ajax code where users type some test c++ code into a codemirror window… I want to store this server side as JSON. I then want to serve this code back to a page and have it load back into codemirror.
An example of the Javascript/ajax -
var codem1 = CodeMirror(document.getElementById(“mycode”),{…}
…
var postinfo = {“jscode”:codem1.getValue()}
$.ajax({url: ‘http://domain/’,type: ‘POST’,dataType: ‘json’,data: postinfo})
I can then collect the POST and save it server side.
What are the best practices to load the code back into codemirror safely?
for example, after retrieval from server -
JS example -
codem1.setvalue(xxxxxxxxxx);
How does codemirror handle escape characters etc? Is it possible that during the the parsing into codemirror… some evil code could escape and the JS could be executed client-side?
codemirror does for example convert newline characters “\n” automatically etc.