gavinchou commented on code in PR #33255: URL: https://github.com/apache/doris/pull/33255#discussion_r1551371971
########## cloud/src/meta-service/meta_service_resource.cpp: ########## @@ -308,6 +308,61 @@ static std::string next_available_vault_id(const InstanceInfoPB& instance) { return std::to_string(prev + 1); } +namespace detail { + +// Removes any trailing `c` in `str` +void strip_trailing(std::string& str, char c) { + size_t end = str.find_last_not_of(c); + if (end == std::string::npos) { + str = ""; + } else { + str.resize(end + 1); + } +} + +// Removes any leading `c` in `str` +void strip_leading(std::string& str, char c) { + size_t start = str.find_first_not_of(c); + if (start == std::string::npos) { + str = ""; + } else if (start > 0) { + str = str.substr(start); + } +} + +// Validate and normalize hdfs prefix. Return true if prefix is valid. +bool normalize_hdfs_prefix(std::string& prefix) { + if (prefix.empty()) { + return true; + } + + if (prefix.find("://") != std::string::npos) { + // Should not contain scheme + return false; + } + + strip_trailing(prefix, ' '); + strip_leading(prefix, ' '); + strip_trailing(prefix, '/'); + return true; +} + +// Validate and normalize hdfs fs_name. Return true if fs_name is valid. +bool normalize_hdfs_fs_name(std::string& fs_name) { + if (fs_name.empty()) { + return false; + } + + // Should check scheme existence? + + strip_trailing(fs_name, ' '); + strip_leading(fs_name, ' '); Review Comment: should we consider all `white space` chars? ########## cloud/src/meta-service/meta_service_resource.cpp: ########## @@ -308,6 +308,61 @@ static std::string next_available_vault_id(const InstanceInfoPB& instance) { return std::to_string(prev + 1); } +namespace detail { + +// Removes any trailing `c` in `str` +void strip_trailing(std::string& str, char c) { + size_t end = str.find_last_not_of(c); + if (end == std::string::npos) { + str = ""; + } else { + str.resize(end + 1); + } +} + +// Removes any leading `c` in `str` +void strip_leading(std::string& str, char c) { + size_t start = str.find_first_not_of(c); + if (start == std::string::npos) { + str = ""; + } else if (start > 0) { + str = str.substr(start); + } +} + +// Validate and normalize hdfs prefix. Return true if prefix is valid. +bool normalize_hdfs_prefix(std::string& prefix) { + if (prefix.empty()) { + return true; + } + + if (prefix.find("://") != std::string::npos) { + // Should not contain scheme + return false; + } + + strip_trailing(prefix, ' '); + strip_leading(prefix, ' '); + strip_trailing(prefix, '/'); + return true; +} + +// Validate and normalize hdfs fs_name. Return true if fs_name is valid. +bool normalize_hdfs_fs_name(std::string& fs_name) { Review Comment: ditto ########## cloud/src/meta-service/meta_service_resource.cpp: ########## @@ -308,6 +308,61 @@ static std::string next_available_vault_id(const InstanceInfoPB& instance) { return std::to_string(prev + 1); } +namespace detail { + +// Removes any trailing `c` in `str` +void strip_trailing(std::string& str, char c) { + size_t end = str.find_last_not_of(c); + if (end == std::string::npos) { + str = ""; + } else { + str.resize(end + 1); + } +} + +// Removes any leading `c` in `str` +void strip_leading(std::string& str, char c) { + size_t start = str.find_first_not_of(c); + if (start == std::string::npos) { + str = ""; + } else if (start > 0) { + str = str.substr(start); + } +} + +// Validate and normalize hdfs prefix. Return true if prefix is valid. +bool normalize_hdfs_prefix(std::string& prefix) { Review Comment: Add comment that, if the input is invalid, it is not touched after calling this function. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org