diff --git a/include/json_compiler.h b/include/json_compiler.h index d561565..7760268 100644 --- a/include/json_compiler.h +++ b/include/json_compiler.h @@ -57,6 +57,7 @@ private: bool ParseAttribute(const Json::Value &arrayItem, const ResourceItem &resourceItem, std::vector &values) const; bool CheckPluralValue(const Json::Value &arrayItem, const ResourceItem &resourceItem) const; + bool CheckColorValue(const char *s) const; std::map handles_; static const std::string TAG_NAME; static const std::string TAG_VALUE; diff --git a/src/json_compiler.cpp b/src/json_compiler.cpp index 9015f22..df96f8e 100644 --- a/src/json_compiler.cpp +++ b/src/json_compiler.cpp @@ -298,6 +298,11 @@ bool JsonCompiler::CheckJsonStringValue(const Json::Value &valueNode, const Reso string value = valueNode.asString(); ResType type = resourceItem.GetResType(); + if (type == ResType::COLOR && !CheckColorValue(value.c_str())) { + string error = "invaild color '" + value + "', in " + resourceItem.GetFilePath(); + cerr << "Error: " << error << endl; + return false; + } regex ref("^\\$.+:"); smatch result; if (regex_search(value, result, ref) && !regex_match(result[0].str(), regex(REFS.at(type)))) { @@ -464,6 +469,19 @@ bool JsonCompiler::CheckPluralValue(const Json::Value &arrayItem, const Resource } return true; } + +bool JsonCompiler::CheckColorValue(const char *s) const +{ + if (s == nullptr) { + return false; + } + // color regex + string regColor = "^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$"; + if (regex_match(s, regex("^\\$.*")) || regex_match(s, regex(regColor))) { + return true; + } + return false; +} } } } diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 4f05176..159b79b 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -267,6 +267,7 @@ string ResourceUtil::RealPath(const string &path) { return FileEntry::RealPath(path); } + bool ResourceUtil::IslegalPath(const string &path) { return path == "element" || path == "media" || path == "profile";