parsing - Avoiding loop when at run-time parse a javascript code -


I can javascript code in a user text area when I realized the JavaScript parser in a web page like:

  var i = 0; I ++; Var y = i * 10; Document.write (y);   

Some output is parsed for generating (for example, document. Written stream, and so on).

When the textarea change event occurs parsing the function occurs.

  function pars (text) {try {.... eval (text); } Hold (e) {.... return {status: wrong, output: ..., ...: ...}; } Return {Status: true, Output: ...., ...: ...}; }   

Everything works well, but I have a problem when a user types a loop in the text area (e.g., for (var i = 0; i & Lt; 10;) , while (true) ) because the application goes into the loop.

To avoid this problem, I will ask you some questions / solutions for this problem:

  1. Are there some JavaScript libraries or functions that eval allow a javascript code but loop-free?
  2. Can I ask for a certain time to execute my parse function? After such a time, I will create an exception that prevents the Evil Function.
  3. I can call a checkIfThereAreLoops function before calling eval (text), which for (var i = 0; i & lt; 10;) or while (true) . Is this a good solution? Can I use a regular expression to find these patterns?

    If you are trying to see whether the arbitrary code ends, Neither will it be for a time.

    So you have the right to think that you will need a preventive measure on your parse function, either exiting or unsafe from unsafe input.

    I do not know about this that there is no way to disrupt the eval despite implementing the 'This script is running very long' without the browser , So you want to clear the input and do not evaluate anything with any loop: it will be difficult because you do not search for the creation of , while etc. and to avoid recursive function calls can do.

    This is a difficult problem to solve ...

    An exclusive variable declaration at the top of the code entered in a 'Hummy' solution Can be inserted (definitely hidden) and this variable is broken, allowing the construction of second line Ese insertion and syntax from inside the input code is broken. Please enter prudential check on each increment if unique_var> Exit 99999; (Where is the limit of 99999 that you apply).

    It should stop at least unlimited bounds.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -