title: Is there any encoding scheme that is resilient to double encoding?
body: <p>Is there any encoding scheme that is resilient to double (or more) encodes or decodes and also safe against XSS and SQL injection attacks?
  To illustrate:</p>
  
  <pre><code>enc(A) --&gt; A'
  enc(A') --&gt; A'
  </code></pre>
  
  <p>and subsequently:</p>
  
  <pre><code>dec(A') --&gt; A
  dec(A) --&gt; A
  </code></pre>
  
  <p>Where this would be useful is in a MVC framework, where we specify the content be encoded prior to being sent to the Controller. Howerver, the UI is multiple layers and may (inadvertently) double encode by both the subview and its parent.</p>