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="cat"&page=2. Percent-encoding ", < and > keeps the URL complete and still keeps it inside the attribute.
This commit is contained in:
parent
de6ac2392c
commit
58d4f6aa2c
3 changed files with 19 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue