Fixed non-working Wikimedia links with ? character in a title

Signed-off-by: alnzrv <7187657+alnzrv@users.noreply.github.com>
This commit is contained in:
alnzrv 2024-07-02 21:07:13 +02:00 committed by GitHub
parent 52b616e18c
commit a7aa9a9b6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,11 +50,22 @@ std::string Metadata::GetWikiURL() const
return ToWikiURL(string(Get(FMD_WIKIPEDIA)));
}
string Metadata::ToWikimediaCommonsURL(std::string const & v)
string Metadata::ToWikimediaCommonsURL(std::string v)
{
if (v.empty())
return v;
// ? character should be corrected to form a valid URL's path.
for (auto i = 0; i < v.size(); ++i)
{
auto & c = v[i];
if (c == '?')
{
c = '%';
v.insert(i + 1, "3F"); // ? => %3F
}
}
return "https://commons.wikimedia.org/wiki/" + v;
}