Skip to content

fix: allow html_to_text/1 to receive nil, e.g. for empty event descriptions

pots damn requested to merge potsdamn/mobilizon:html_to_text-nil into main

Our issue: https://git.potsda.mn/potsda.mn/mobilizon/issues/34

This fixes an issue when accessing the ICS instance feed, while one event description is nil. The root cause is, that String.replace/4 doesn't accept nil as first argument.

$ curl https://rotes.potsda.mn/feed/instance/ics
Bad feed
Dec 09 21:22:27 potsdam mobilizon[2096]: 21:22:27.394 request_id=F59Dc27DDf-ncecABu1h [warning] Unable to find feed data cached for key instance, returned {:error, %Cachex.ExecutionError{message: "no function clause matching in String.replace/4", stack: [{String, :replace, [nil, ~r/<li>/, "\\g{1}- ", [global: true]], [file: ~c"lib/string.ex", line: 1520]}, {Mobilizon.Service.Formatter.HTML, :html_to_text, 1, [file: ~c"lib/service/formatter/html.ex", line: 47]}, {Mobilizon.Service.Export.ICalendar, :do_export_event, 1, [file: ~c"lib/service/export/icalendar.ex", line: 127]}, {Enum, :"-map/2-lists^map/1-1-", 2, [file: ~c"lib/enum.ex", line: 1693]}, {Enum, :"-map/2-lists^map/1-1-", 2, [file: ~c"lib/enum.ex", line: 1693]}, {Mobilizon.Service.Export.ICalendar, :fetch_instance_feed, 0, [file: ~c"lib/service/export/icalendar.ex", line: 66]}, {Mobilizon.Service.Export.ICalendar, :create_cache, 1, [file: ~c"lib/service/export/icalendar.ex", line: 59]}, {Cachex.Services.Courier, :"-handle_call/3-fun-0-", 5, [file: ~c"lib/cachex/services/courier.ex", line: 77]}, {Cachex.Services.Courier, :dispatch, 3, [file: ~c"lib/cachex/services/courier.ex", line: 44]}, {Cachex, :fetch, 4, [file: ~c"lib/cachex.ex", line: 693]}, {Mobilizon.Web.FeedController, :return_data, 4, [file: ~c"lib/web/controllers/feed_controller.ex", line: 74]}, {Mobilizon.Web.FeedController, :action, 2, [file: ~c"lib/web/controllers/feed_controller.ex", line: 1]}, {Mobilizon.Web.FeedController, :phoenix_controller_pipeline, 2, [file: ~c"lib/web/controllers/feed_controller.ex", line: 1]}, {Phoenix.Router, :__call__, 5, [file: ~c"lib/phoenix/router.ex", line: 432]}]}}

Merge request reports