fix(formatter): percent-encode quotes in Markdown URLs instead of cutting

Cutting the URL at the first quote dropped the rest of valid links such
as ?q=&quot;cat&quot;&page=2. Percent-encoding ", < and > keeps the URL
complete and still keeps it inside the attribute.
This commit is contained in:
Lain Soykaf 2026-10-22 16:28:06 +04:00
commit 58d4f6aa2c
No known key found for this signature in database
3 changed files with 19 additions and 11 deletions

View file

@ -252,9 +252,13 @@ defmodule Pleroma.Formatter do
defp sanitize_markdown_url(value, name) do
if String.downcase(to_string(name)) in ["href", "src"] do
value
|> String.split(~r/["<>]/, parts: 2)
|> hd()
# Percent-encode instead of cutting, so the URL stays complete but can
# never close the attribute or open a tag.
String.replace(value, ~r/["<>]/, fn
"\"" -> "%22"
"<" -> "%3C"
">" -> "%3E"
end)
else
value
end