%)" +
+ "( ?[-=_]{2,})))+(\\Q" + HTML_NEWLINE + "\\E|$)))");
/**
* Convert a text string into an HTML document.
@@ -329,8 +334,7 @@ public class HtmlConverter {
HTML_BLOCKQUOTE_END + "$1"
);
- // Replace lines of -,= or _ with horizontal rules
- text = text.replaceAll("\\s*([-=_]{30,}+)\\s*", "
");
+ text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("
");
StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
diff --git a/k9mail/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java b/k9mail/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java
index 57e6105e6..28ce3cf3f 100644
--- a/k9mail/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java
+++ b/k9mail/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java
@@ -207,4 +207,105 @@ public class HtmlConverterTest {
"http://example.com/" +
"", outputBuffer.toString());
}
+
+ @Test
+ public void issue2259Spec() {
+ String text = "text\n" +
+ "---------------------------\n" +
+ "some other text\n" +
+ "===========================\n" +
+ "more text\n" +
+ "-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" +
+ "scissors below\n" +
+ "-- >8 --\n" +
+ "other direction\n" +
+ "-- 8< --\n" +
+ "end";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("text
" +
+ "some other text
" +
+ "more text
" +
+ "scissors below
" +
+ "other direction
" +
+ "end
",
+ result);
+ }
+
+ @Test
+ public void dashesContainingSpacesIgnoredAsHR() {
+ String text = "hello\n--- --- --- --- ---\nfoo bar";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("hello
--- --- --- --- ---
foo bar
",
+ result);
+ }
+
+ @Test
+ public void mergeConsecutiveBreaksIntoOne() {
+ String text = "hello\n------------\n---------------\nfoo bar";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("hello
foo bar
", result);
+ }
+
+ @Test
+ public void dashedHorizontalRulePrefixedWithTextIgnoredAsHR() {
+ String text = "hello----\n\n";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("hello----
", result);
+ }
+
+ @Test
+ public void doubleMinusIgnoredAsHR() {
+ String text = "--\n";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("--
", result);
+ }
+
+ @Test
+ public void doubleEqualsIgnoredAsHR() {
+ String text = "==\n";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("==
", result);
+ }
+
+ @Test
+ public void doubleUnderscoreIgnoredAsHR() {
+ String text = "__\n";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("__
", result);
+ }
+
+ @Test
+ public void anyTripletIsHRuledOut() {
+ String text = "--=\n-=-\n===\n___\n\n";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("
", result);
+ }
+
+ @Test
+ public void replaceSpaceSeparatedDashesWithHR() {
+ String text = "hello\n---------------------------\nfoo bar";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("hello
foo bar
", result);
+ }
+
+ @Test
+ public void replacementWithHRAtBeginning() {
+ String text = "---------------------------\nfoo bar";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("
foo bar
", result);
+ }
+
+ @Test
+ public void replacementWithHRAtEnd() {
+ String text = "hello\n__________________________________";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("hello
", result);
+ }
+
+ @Test
+ public void replacementOfScissorsByHR() {
+ String text = "hello\n-- %< -------------- >8 --\nworld\n";
+ String result = HtmlConverter.textToHtml(text);
+ assertEquals("hello
world
", result);
+ }
}