校验颜色值合法性

Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
fangyunzhong
2022-09-19 12:18:13 +08:00
parent 1143f82813
commit 04f68a0f9e
3 changed files with 20 additions and 0 deletions
+1
View File
@@ -57,6 +57,7 @@ private:
bool ParseAttribute(const Json::Value &arrayItem, const ResourceItem &resourceItem,
std::vector<std::string> &values) const;
bool CheckPluralValue(const Json::Value &arrayItem, const ResourceItem &resourceItem) const;
bool CheckColorValue(const char *s) const;
std::map<ResType, HandleResource> handles_;
static const std::string TAG_NAME;
static const std::string TAG_VALUE;
+18
View File
@@ -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;
}
}
}
}
+1
View File
@@ -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";