playframework/twirl — pull request #48 by jroper (2014-10-31 05:10:22+00:00)
Title: HtmlFormat.escape loop performance

The following loop could probably be a bit faster if a `while` loop is used instead of a `foreach` expression. Might save some character boxing and the code would still be pretty simple.

```scala
def escape(text: String): Html = {
// Using our own algorithm here because commons lang escaping wasn't designed for protecting against XSS, and there
// don't seem to be any other good generic escaping tools out there.
val sb = new StringBuilder(text.length)
text.foreach {
case '<' => sb.append("<")
case '>' => sb.append(">")
case '"' => sb.append(""")
case '\'' => sb.append("'")
case '&' => sb.append("&")
case c => sb += c
}
new Html(sb.toString)
}
```

Cc @pvlugter.