Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: components/update_client/utils.cc

Issue 2102083002: Allow component installers to specify a map of installer attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/update_client/utils.h ('k') | components/update_client/utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/update_client/utils.cc
diff --git a/components/update_client/utils.cc b/components/update_client/utils.cc
index 90bbc1197f945f19d7d2493afa9c16c7735b98f7..717984d8999f26d96ea4dfb5ab59bc377b42af53 100644
--- a/components/update_client/utils.cc
+++ b/components/update_client/utils.cc
@@ -239,23 +239,42 @@ bool IsValidBrand(const std::string& brand) {
}) == brand.end();
}
-bool IsValidAp(const std::string& ap) {
- const size_t kMaxApSize = 256;
- if (ap.size() > kMaxApSize)
+// Helper function.
+// Returns true if |part| matches the expression
+// ^[<special_chars>a-zA-Z0-9]{min_length,max_length}$
+bool IsValidInstallerAttributePart(const std::string& part,
+ const std::string& special_chars,
+ size_t min_length,
+ size_t max_length) {
+ if (part.size() < min_length || part.size() > max_length)
return false;
- return std::find_if_not(ap.begin(), ap.end(), [](char ch) {
+ return std::find_if_not(part.begin(), part.end(), [&special_chars](char ch) {
if (base::IsAsciiAlpha(ch) || base::IsAsciiDigit(ch))
return true;
- const char kSpecialChars[] = "+-_=";
- for (auto c : kSpecialChars) {
+ for (auto c : special_chars) {
if (c == ch)
return true;
}
return false;
- }) == ap.end();
+ }) == part.end();
+}
+
+// Returns true if the |name| parameter matches ^[-_a-zA-Z0-9]{1,256}$ .
+bool IsValidInstallerAttributeName(const std::string& name) {
+ return IsValidInstallerAttributePart(name, "-_", 1, 256);
+}
+
+// Returns true if the |value| parameter matches ^[-.,;+_=a-zA-Z0-9]{0,256}$ .
+bool IsValidInstallerAttributeValue(const std::string& value) {
+ return IsValidInstallerAttributePart(value, "-.,;+_=", 0, 256);
+}
+
+bool IsValidInstallerAttribute(const InstallerAttribute& attr) {
+ return IsValidInstallerAttributeName(attr.first) &&
+ IsValidInstallerAttributeValue(attr.second);
}
void RemoveUnsecureUrls(std::vector<GURL>* urls) {
« no previous file with comments | « components/update_client/utils.h ('k') | components/update_client/utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698