mirror of
https://github.com/transmission/transmission
synced 2025-02-22 06:00:41 +00:00
fix: allow malformed magnet links to be added (#2410)
This commit is contained in:
parent
c9f8f150ea
commit
be1e46383d
1 changed files with 14 additions and 3 deletions
|
@ -301,14 +301,25 @@ std::optional<tr_url_parsed_t> tr_urlParse(std::string_view url)
|
||||||
{
|
{
|
||||||
url = tr_strvStrip(url);
|
url = tr_strvStrip(url);
|
||||||
|
|
||||||
|
auto parsed = tr_url_parsed_t{};
|
||||||
|
parsed.full = url;
|
||||||
|
|
||||||
|
// So many magnet links are malformed, e.g. not escaping text
|
||||||
|
// in the display name, that we're better off handling magnets
|
||||||
|
// as a special case before even scanning for invalid chars.
|
||||||
|
auto constexpr MagnetStart = "magnet:?"sv;
|
||||||
|
if (tr_strvStartsWith(url, MagnetStart))
|
||||||
|
{
|
||||||
|
parsed.scheme = "magnet"sv;
|
||||||
|
parsed.query = url.substr(std::size(MagnetStart));
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
if (!urlCharsAreValid(url))
|
if (!urlCharsAreValid(url))
|
||||||
{
|
{
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parsed = tr_url_parsed_t{};
|
|
||||||
parsed.full = url;
|
|
||||||
|
|
||||||
// scheme
|
// scheme
|
||||||
parsed.scheme = tr_strvSep(&url, ':');
|
parsed.scheme = tr_strvSep(&url, ':');
|
||||||
if (std::empty(parsed.scheme))
|
if (std::empty(parsed.scheme))
|
||||||
|
|
Loading…
Reference in a new issue