From 04f68a0f9e5c878b78648fc18eadf8914bbc760a Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Mon, 19 Sep 2022 12:18:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=A2=9C=E8=89=B2=E5=80=BC?= =?UTF-8?q?=E5=90=88=E6=B3=95=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangyunzhong --- include/json_compiler.h | 1 + src/json_compiler.cpp | 18 ++++++++++++++++++ src/resource_util.cpp | 1 + 3 files changed, 20 insertions(+) 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";