Fix errant RML tag in mod menu and insert breaks for newlines when setting element text

This commit is contained in:
Mr-Wiseguy 2025-03-12 00:06:48 -04:00
parent bb10d5d090
commit 51c6263f13
3 changed files with 23 additions and 3 deletions

View File

@ -272,10 +272,30 @@ bool Element::is_enabled() const {
return enabled && !disabled_from_parent;
}
// Adapted from RmlUi's `EncodeRml`.
std::string escape_rml(std::string_view string)
{
std::string result;
result.reserve(string.size());
for (char c : string)
{
switch (c)
{
case '<': result += "&lt;"; break;
case '>': result += "&gt;"; break;
case '&': result += "&amp;"; break;
case '"': result += "&quot;"; break;
case '\n': result += "<br/>"; break;
default: result += c; break;
}
}
return result;
}
void Element::set_text(std::string_view text) {
if (can_set_text) {
// Escape the string into Rml to prevent element injection.
base->SetInnerRML(Rml::StringUtilities::EncodeRml(std::string(text)));
base->SetInnerRML(escape_rml(text));
}
else {
assert(false && "Attempted to set text of an element that cannot have its text set.");

View File

@ -61,7 +61,7 @@ public:
virtual ~Element();
void clear_children();
bool remove_child(ResourceId child);
bool remove_child(Element *child) { remove_child(child->get_resource_id()); }
bool remove_child(Element *child) { return remove_child(child->get_resource_id()); }
void add_style(Style *style, std::string_view style_name);
void add_style(Style *style, const std::initializer_list<std::string_view> &style_names);
void set_enabled(bool enabled);

View File

@ -83,7 +83,7 @@ void ModDetailsPanel::set_mod_details(const recomp::mods::ModDetails& details, c
title_label->set_text(cur_details.display_name);
version_label->set_text(cur_details.version.to_string());
std::string authors_str = "<i>Authors</i>:";
std::string authors_str = "Authors:";
bool first = true;
for (const std::string& author : details.authors) {
authors_str += (first ? " " : ", ") + author;