Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute value supports rml escape #154

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Attribute value supports rml escape
  • Loading branch information
actboy168 committed Dec 10, 2020
commit afecffd956869144266d0f17f5c76ec0d4012ba2
3 changes: 3 additions & 0 deletions Include/RmlUi/Core/StringUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace StringUtilities
/// Encode RML characters, eg. '<' to '&lt;'
RMLUICORE_API String EncodeRml(const String& string);

/// Decode RML characters, eg. '&lt;' to '<'
RMLUICORE_API String DecodeRml(const String& string);

// Replaces all occurences of 'search' in 'subject' with 'replace'.
RMLUICORE_API String Replace(String subject, const String& search, const String& replace);
// Replaces all occurences of 'search' in 'subject' with 'replace'.
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/BaseXMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ bool BaseXMLParser::ReadAttributes(XMLAttributes& attributes, bool& parse_raw_xm
if (attributes_for_inner_xml_data.count(attribute) == 1)
parse_raw_xml_content = true;

attributes[attribute] = value;
attributes[attribute] = StringUtilities::DecodeRml(value);

// Check for the end of the tag.
if (PeekString("/", false) || PeekString(">", false))
Expand Down
39 changes: 39 additions & 0 deletions Source/Core/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,45 @@ RMLUICORE_API String StringUtilities::EncodeRml(const String& string)
return result;
}

String StringUtilities::DecodeRml(const String& s)
{
String result;
result.reserve(s.size());
for (size_t i = 0; i < s.size();)
{
if (s[i] == '&')
{
if (s[i+1] == 'l' && s[i+2] == 't' && s[i+3] == ';')
{
result += "<";
i += 4;
continue;
}
else if (s[i+1] == 'g' && s[i+2] == 't' && s[i+3] == ';')
{
result += ">";
i += 4;
continue;
}
else if (s[i+1] == 'a' && s[i+2] == 'm' && s[i+3] == 'p' && s[i+4] == ';')
{
result += "&";
i += 5;
continue;
}
else if (s[i+1] == 'q' && s[i+2] == 'u' && s[i+3] == 'o' && s[i+4] == 't' && s[i+5] == ';')
{
result += "\"";
i += 6;
continue;
}
}
result += s[i];
i += 1;
}
return result;
}

String StringUtilities::Replace(String subject, const String& search, const String& replace)
{
size_t pos = 0;
Expand Down