Fix bug in EmailSectionExtractor when text ends with an empty line
This commit is contained in:
parent
990765ac6e
commit
8f334dd0c3
2 changed files with 35 additions and 6 deletions
|
@ -96,12 +96,10 @@ class EmailSectionExtractor private constructor(val text: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun completeLastSection() {
|
private fun completeLastSection() {
|
||||||
if (!isStartOfLine) {
|
if (quoteDepth == 0) {
|
||||||
if (quoteDepth == 0) {
|
sectionBuilder.addSegment(0, sectionStartIndex, text.length)
|
||||||
sectionBuilder.addSegment(0, sectionStartIndex, text.length)
|
} else if (!isStartOfLine) {
|
||||||
} else {
|
sectionBuilder.addSegment(spaces, startOfContentIndex, text.length)
|
||||||
sectionBuilder.addSegment(spaces, startOfContentIndex, text.length)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
appendSection()
|
appendSection()
|
||||||
|
|
|
@ -26,6 +26,19 @@ class EmailSectionExtractorTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun simpleMessageEndingWithTwoNewlines() {
|
||||||
|
val message = "Hello\n\n"
|
||||||
|
|
||||||
|
val sections = EmailSectionExtractor.extract(message)
|
||||||
|
|
||||||
|
assertThat(sections.size).isEqualTo(1)
|
||||||
|
with(sections[0]) {
|
||||||
|
assertThat(quoteDepth).isEqualTo(0)
|
||||||
|
assertThat(toString()).isEqualTo(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun quoteFollowedByReply() {
|
fun quoteFollowedByReply() {
|
||||||
val message = """
|
val message = """
|
||||||
|
@ -81,6 +94,24 @@ class EmailSectionExtractorTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun quoteEndingWithEmptyLineButNoNewline() {
|
||||||
|
val message = """
|
||||||
|
> Quoted text
|
||||||
|
> """.trimIndent()
|
||||||
|
|
||||||
|
val sections = EmailSectionExtractor.extract(message)
|
||||||
|
|
||||||
|
assertThat(sections.size).isEqualTo(1)
|
||||||
|
with(sections[0]) {
|
||||||
|
assertThat(quoteDepth).isEqualTo(1)
|
||||||
|
// Note: "Quoted text\n\n" would be a better representation of the quoted text. The goal of this test is
|
||||||
|
// not to preserve the current behavior of only ending in one newline, but to make sure we don't add the
|
||||||
|
// last line twice.
|
||||||
|
assertThat(toString()).isEqualTo("Quoted text\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun chaosQuoting() {
|
fun chaosQuoting() {
|
||||||
val message = """
|
val message = """
|
||||||
|
|
Loading…
Reference in a new issue