diff --git a/src/main/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapper.kt b/src/main/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapper.kt index 8d75e15..cec8838 100644 --- a/src/main/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapper.kt +++ b/src/main/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapper.kt @@ -16,11 +16,16 @@ fun TalkingKotlinItem.toTalkingKotlinEntry(): TalkingKotlin { contentUrl = link, thumbnailUrl = image.href, audioUrl = enclosure.url, - summary = summary, + summary = summary.sanitize(), duration = duration.toFormattedDuration(), ) } +private fun String.sanitize(): String { + return replace(Regex("[\n\r]+"), " ") + .replace(Regex("\\s+"), " ") +} + private fun String.toFormattedDuration(): String { val parts = split(":").map { it.toInt() } val duration = Duration.ofHours(parts[0].toLong()) diff --git a/src/test/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapperTest.kt b/src/test/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapperTest.kt index 47fe3ac..b09a67e 100644 --- a/src/test/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapperTest.kt +++ b/src/test/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/TalkingKotlinEntryMapperTest.kt @@ -17,7 +17,7 @@ class TalkingKotlinEntryMapperTest { contentUrl = "url", audioUrl = "audio-url", thumbnailUrl = "image-url", - summary = "summary", + summary = "summary line 1 line 2 line 3", duration = "43min.", ) val actual = TalkingKotlinItem( @@ -26,7 +26,7 @@ class TalkingKotlinEntryMapperTest { pubDate = "Tue, 22 Nov 2022 16:30:09 +0000", link = "url", duration = "00:43:14", - summary = "summary", + summary = "summary line 1\n\n line 2 \r\n line 3", enclosure = TalkingKotlinItem.Enclosure(url = "audio-url"), image = TalkingKotlinItem.Image(href = "image-url"), ).toTalkingKotlinEntry()