Browse Source

Debugger: Enable listing of hidden elements, and escape attribute values.

Michael Ragazzon 6 years ago
parent
commit
4be83d440e

+ 3 - 0
Include/RmlUi/Core/StringUtilities.h

@@ -82,6 +82,9 @@ namespace StringUtilities
 	/// Converts upper-case characters in string to lower-case.
 	RMLUICORE_API String ToLower(const String& string);
 
+	/// Encode RML characters, eg. '<' to '&lt;'
+	RMLUICORE_API String EncodeRml(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'.

+ 18 - 0
Source/Core/StringUtilities.cpp

@@ -92,6 +92,24 @@ String StringUtilities::ToLower(const String& string) {
 	return str_lower;
 }
 
+RMLUICORE_API String StringUtilities::EncodeRml(const String& string)
+{
+	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;
+		default: result += c; break;
+		}
+	}
+	return result;
+}
+
 String StringUtilities::Replace(String subject, const String& search, const String& replace)
 {
 	size_t pos = 0;

+ 2 - 2
Source/Debugger/ElementInfo.cpp

@@ -495,7 +495,7 @@ void ElementInfo::UpdateSourceElement()
 			{
 				auto& name = pair.first;
 				auto& variant = pair.second;
-				Core::String value = variant.Get<Core::String>();
+				Core::String value = Core::StringUtilities::EncodeRml(variant.Get<Core::String>());
 				if(name != "class" && name != "style" && name != "id") 
 					attributes += Core::CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
 			}
@@ -619,7 +619,7 @@ void ElementInfo::UpdateSourceElement()
 		Core::String children;
 		if (source_element != nullptr)
 		{
-			for (int i = 0; i < source_element->GetNumChildren(); i++)
+			for (int i = 0; i < source_element->GetNumChildren(true); i++)
 			{
 				Core::Element* child = source_element->GetChild(i);