Skip to content

Commit

Permalink
Merge pull request thunderbird#3025 from k9mail/GH-3018_fix_text2html
Browse files Browse the repository at this point in the history
Revert to old way of replacing ASCII lines with <hr> tag
  • Loading branch information
cketti authored Jan 2, 2018
2 parents 1506c6d + b49af84 commit 11fae34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;

import android.text.Annotation;
import android.text.Editable;
Expand Down Expand Up @@ -179,11 +178,6 @@ private static String simpleTextToHtml(String text) {
"style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid $$COLOR$$; padding-left: 1ex;\">";
private static final String HTML_BLOCKQUOTE_END = "</blockquote>";
private static final String HTML_NEWLINE = "<br />";
private static final Pattern ASCII_PATTERN_FOR_HR = Pattern.compile(
"(^|\\Q" + HTML_NEWLINE + "\\E)\\s*((\\Q" + HTML_NEWLINE + "\\E)*" +
"((((\\Q" + HTML_NEWLINE + "\\E){0,2}([-=_]{3,})(\\Q" + HTML_NEWLINE +
"\\E){0,2})|(([-=_]{2,} ?)(8&lt;|<gt>8|%&lt;|<gt>%)" +
"( ?[-=_]{2,})))+(\\Q" + HTML_NEWLINE + "\\E|$)))");

/**
* Convert a text string into an HTML document.
Expand Down Expand Up @@ -276,7 +270,7 @@ public static String textToHtml(String text) {
HTML_BLOCKQUOTE_END + "$1"
);

text = ASCII_PATTERN_FOR_HR.matcher(text).replaceAll("<hr>");
text = text.replaceAll("\\s*([-=_]{30,}+)\\s*", "<hr>");

StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.fsck.k9.K9RobolectricTestRunner;
import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
Expand Down Expand Up @@ -194,6 +195,7 @@ public void testPreserveSpacesAtFirstForSpecialCharacters() {
}

@Test
@Ignore("Disabled due to temporary fix for issue #3018")
public void issue2259Spec() {
String text = "text\n" +
"---------------------------\n" +
Expand Down Expand Up @@ -225,6 +227,7 @@ public void dashesContainingSpacesIgnoredAsHR() {
}

@Test
@Ignore("Disabled due to temporary fix for issue #3018")
public void mergeConsecutiveBreaksIntoOne() {
String text = "hello\n------------\n---------------\nfoo bar";
String result = HtmlConverter.textToHtml(text);
Expand Down Expand Up @@ -260,34 +263,39 @@ public void doubleUnderscoreIgnoredAsHR() {
}

@Test
@Ignore("Disabled due to temporary fix for issue #3018")
public void anyTripletIsHRuledOut() {
String text = "--=\n-=-\n===\n___\n\n";
String result = HtmlConverter.textToHtml(text);
assertEquals("<pre class=\"k9mail\"><hr></pre>", result);
}

@Test
@Ignore("Disabled due to temporary fix for issue #3018")
public void replaceSpaceSeparatedDashesWithHR() {
String text = "hello\n---------------------------\nfoo bar";
String result = HtmlConverter.textToHtml(text);
assertEquals("<pre class=\"k9mail\">hello<hr>foo bar</pre>", result);
}

@Test
@Ignore("Disabled due to temporary fix for issue #3018")
public void replacementWithHRAtBeginning() {
String text = "---------------------------\nfoo bar";
String result = HtmlConverter.textToHtml(text);
assertEquals("<pre class=\"k9mail\"><hr>foo bar</pre>", result);
}

@Test
@Ignore("Disabled due to temporary fix for issue #3018")
public void replacementWithHRAtEnd() {
String text = "hello\n__________________________________";
String result = HtmlConverter.textToHtml(text);
assertEquals("<pre class=\"k9mail\">hello<hr></pre>", result);
}

@Test
@Ignore("Disabled due to temporary fix for issue #3018")
public void replacementOfScissorsByHR() {
String text = "hello\n-- %< -------------- >8 --\nworld\n";
String result = HtmlConverter.textToHtml(text);
Expand Down

0 comments on commit 11fae34

Please sign in to comment.