1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-07 17:36:07 +00:00

Add support for numeric XML entities to XMLParser

* Add support for decimal numeric entities to String::xml_unescape
* Add more error checks to String::xml_unescape
* Refactor XMLParser to use String::xml_unescape instead of an internal
implementation
This commit is contained in:
Henry Conklin
2021-02-11 09:33:55 -06:00
committed by Rémi Verschelde
parent ed28ce53bf
commit a28beb3048
7 changed files with 255 additions and 92 deletions

View File

@@ -1123,6 +1123,45 @@ bool test_35() {
return state;
}
bool test_36() {
#define CHECK(X) \
if (!(X)) { \
OS::get_singleton()->print("\tFAIL at %s\n", #X); \
return false; \
} else { \
OS::get_singleton()->print("\tPASS\n"); \
}
OS::get_singleton()->print("\n\nTest 36: xml unescape\n");
// Named entities
String input = ""&'<>";
CHECK(input.xml_unescape() == "\"&\'<>");
// Numeric entities
input = "&#x41;&#66;";
CHECK(input.xml_unescape() == "AB");
input = "&#0;&x#0;More text";
String result = input.xml_unescape();
// Didn't put in a leading NUL and terminate the string
CHECK(input.length() > 0);
CHECK(input[0] != '\0');
// Entity should be left as-is if invalid
CHECK(input.xml_unescape() == input);
// Shouldn't consume without ending in a ';'
input = "&#66";
CHECK(input.xml_unescape() == input);
input = "&#x41";
CHECK(input.xml_unescape() == input);
// Invalid characters should make the entity ignored
input = "&#x41SomeIrrelevantText;";
CHECK(input.xml_unescape() == input);
input = "&#66SomeIrrelevantText;";
CHECK(input.xml_unescape() == input);
return true;
}
typedef bool (*TestFunc)();
TestFunc test_funcs[] = {
@@ -1162,6 +1201,7 @@ TestFunc test_funcs[] = {
test_33,
test_34,
test_35,
test_36,
nullptr
};