title: How do I handle unicode user input in Scala safely (esp XML entities)
body: <p>On my website I have a form that takes in some textual user input. All works fine for "normal" characters. However when unicode characters are input... well, the plot thickens.</p>
  
  <p>User inputs something like</p>
  
  <pre><code>やっぱ死にかけてる
  </code></pre>
  
  <p>This comes in to the server as text containing XML entity refs</p>
  
  <pre><code>&amp;#12420;&amp;#12387;&amp;#12401;&amp;#27515;&amp;#12395;&amp;#12363;&amp;#12369;&amp;#12390;&amp;#12427;&amp;#65311;
  </code></pre>
  
  <p>Now, when I want to serve this back to the client in HTML, how do I do it?</p>
  
  <p>If I simply output the string as it is, there could be a chance for a script attack. If I try to encode it with <code>scala.xml.Text</code> it gets converted to:</p>
  
  <pre><code>&amp;amp;#12420;&amp;amp;#12387;&amp;amp;#12401;&amp;amp;#27515;&amp;amp;#12395;&amp;amp;#12363;&amp;amp;#12369;&amp;amp;#12390;&amp;amp;#12427;&amp;amp;#65311;
  </code></pre>
  
  <p>Is there a better ready-made solution in Scala which can detect entity refs and <strong>not</strong> escape them, yet escape XML tags?</p>