From b0d98ff1bbda9fa25515a28bcf0c36314156c66c Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Thu, 22 Apr 2021 14:54:23 -0400 Subject: Add a few errors checks (#119) * Check for repeated names, outnames and offsets Signed-off-by: angie * Check for File inside File Signed-off-by: angie * Error if a ZResource node has a child Signed-off-by: angie * Error if an invalid ZResource name is included in the XML Signed-off-by: angie * error when a ZResource is not in a ZFile Signed-off-by: angie * ups Signed-off-by: angie * Add error if unknown element is found and other fixes * Run format --- ZAPD/ZResource.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'ZAPD/ZResource.cpp') diff --git a/ZAPD/ZResource.cpp b/ZAPD/ZResource.cpp index 9ffcc74..767fc0f 100644 --- a/ZAPD/ZResource.cpp +++ b/ZAPD/ZResource.cpp @@ -1,5 +1,8 @@ #include "ZResource.h" +#include +#include "StringHelper.h" + using namespace std; ZResource::ZResource(ZFile* nParent) @@ -42,7 +45,19 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader) if (reader != nullptr) { if (reader->Attribute("Name") != nullptr) + { name = reader->Attribute("Name"); + static std::regex r("[a-zA-Z_]+[a-zA-Z0-9_]*", + std::regex::icase | std::regex::optimize); + + if (!std::regex_match(name, r)) + { + throw std::domain_error( + StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource " + "with invalid 'Name' attribute.\n", + name.c_str())); + } + } else name = ""; @@ -55,6 +70,14 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader) isCustomAsset = true; else isCustomAsset = false; + + if (!canHaveInner && !reader->NoChildren()) + { + throw std::runtime_error( + StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource '%s' " + "with inner element/child detected.\n", + name.c_str(), reader->Name())); + } } } -- cgit v1.2.3