HtmlSanitizer { public String escapeSingleQuotesAndNewLines(String string) { return string.replaceAll("'", "\\\\'").replaceAll("\r?\n", "\\\\n"); }  String escapeSingleQuotesAndNewLines(String string);  }
@Test public void should_escape_unsafe_characters() throws Exception { HtmlSanitizer htmlSanitizer = new HtmlSanitizer(); assertThat(htmlSanitizer.escapeSingleQuotesAndNewLines("Here\n'goes'\nthe\r\nmessage")) .isEqualTo("Here\\n\\'goes\\'\\nthe\\nmessage"); }