title: Escape string in eval context with JSON.stringify
body: <p>First of all: I know that there are many questions related to escaping, but I did not found a generally working answer so far.
  Say I have this simple toy function for demonstration:</p>
  <pre><code>function f(somePOJO) {
    var s = eval(&quot;'&quot; + JSON.stringify(somePOJO) + &quot;';&quot;); // for demonstration only
    return JSON.parse(s);
  }
  const clone = f({a: 1, b: &quot;c&quot;});
  </code></pre>
  <p>Given an object literal such as <code>{a: 1, b: &quot;c&quot;}</code> (a POJO), <code>f</code> should return a &quot;clone&quot; of it. (Note that I do not really use this approach for cloning or similar, and I am aware that <code>eval</code> is evil and also that it is not even needed here, it's just for demonstration of the escaping problem!)</p>
  <p>This works fine, but only as long as the POJO values do not contain a <code>'</code>. Now of course I could escape the JSON by using something like <code>JSON.stringify(somePOJO).replace(/'/g, &quot;\\'&quot;)</code>. This works if the POJO values contain <code>'</code>, but not if they contain <code>\\'</code>. And this creates a spiral of escaping...</p>
  <p>Is there a solution to this at all?</p>