rust-lang/rust-by-example — pull request #342 by dbbrian (2014-12-20 15:48:40+00:00)
Title: Replace the escapeHTML() by a more efficient one. Close #177

The `escapeHTML()` function in [editor.js](https://github.com/rust-lang/rust-by-example/blob/master/node_modules/gitbook-plugin-rust-playpen/book/editor.js#L134) is a little too optimistic about JavaScript. Chaining `String.replace()` like this...

```JavaScript
function escapeHTML(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'")
.replace(newLineRegex, '
');
}
```

…sadly results in `unsafe` being parsed *six* time, and crash Firefox. Other browsers may optimize this as I haven't seen Safari or Chrome crash.