1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix curl compatibility issues with colorize_url (#14615)

Also move the escape code safety check to guiOpenURL.
This commit is contained in:
sfan5 2024-05-09 11:31:10 +02:00 committed by GitHub
parent 780543f0a2
commit 59bf1d8cd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 20 deletions

View file

@ -42,6 +42,19 @@ GUIOpenURLMenu::GUIOpenURLMenu(gui::IGUIEnvironment* env,
{
}
static std::string maybe_colorize_url(const std::string &url)
{
// Forbid escape codes in URL
if (url.find('\x1b') != std::string::npos) {
throw std::runtime_error("URL contains escape codes");
}
#ifdef HAVE_COLORIZE_URL
return colorize_url(url);
#else
return url;
#endif
}
void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
{
@ -70,16 +83,12 @@ void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
*/
bool ok = true;
std::string text;
#ifdef USE_CURL
try {
text = colorize_url(url);
text = maybe_colorize_url(url);
} catch (const std::exception &e) {
text = std::string(e.what()) + " (url = " + url + ")";
ok = false;
}
#else
text = url;
#endif
/*
Add stuff