From 5030b755a0880a022d0656598b591cb47ebd7dc5 Mon Sep 17 00:00:00 2001 From: 778a69cd <778a69cd@potsda.mn> Date: Sat, 9 Dec 2023 21:48:23 +0100 Subject: [PATCH] fix: allow html_to_text to receive nil, e.g. for empty event descriptions Fixes https://git.potsda.mn/potsda.mn/mobilizon/issues/34 Signed-off-by: Thomas Citharel --- lib/service/formatter/html.ex | 4 +++- test/service/export/icalendar_test.exs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/service/formatter/html.ex b/lib/service/formatter/html.ex index 67948d030..79a1f500c 100644 --- a/lib/service/formatter/html.ex +++ b/lib/service/formatter/html.ex @@ -41,7 +41,9 @@ defmodule Mobilizon.Service.Formatter.HTML do def strip_tags_and_insert_spaces(html), do: html - @spec html_to_text(String.t()) :: String.t() + @spec html_to_text(String.t() | nil) :: String.t() | nil + def html_to_text(nil), do: nil + def html_to_text(html) do html |> String.replace(~r/
  • /, "\\g{1}- ", global: true) diff --git a/test/service/export/icalendar_test.exs b/test/service/export/icalendar_test.exs index eca1451e3..0b0361577 100644 --- a/test/service/export/icalendar_test.exs +++ b/test/service/export/icalendar_test.exs @@ -44,11 +44,13 @@ defmodule Mobilizon.Service.ICalendarTest do %Event{} = event = insert(:event, title: "I'm public") %Event{} = event2 = insert(:event, visibility: :private, title: "I'm private") %Event{} = event3 = insert(:event, title: "Another public") + %Event{} = event4 = insert(:event, title: "No description", description: nil) {:commit, ics} = ICalendarService.create_cache("instance") assert ics =~ event.title refute ics =~ event2.title assert ics =~ event3.title + assert ics =~ event4.title end test "with 50 events" do