From 7c96027c39176ab9b773aae1ed2942f3e549319b Mon Sep 17 00:00:00 2001 From: Somesh Chandimal Date: Sun, 18 Aug 2024 15:21:19 +0530 Subject: [PATCH] fix trim issue in frontend input --- src/util/Utils.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/util/Utils.cpp b/src/util/Utils.cpp index 7cddf831..07c1bbcf 100644 --- a/src/util/Utils.cpp +++ b/src/util/Utils.cpp @@ -168,11 +168,19 @@ std::vector Utils::getHostListFromProperties() { } static inline std::string trim_right_copy(const std::string &s, const std::string &delimiters) { - return s.substr(0, s.find_last_not_of(delimiters) + 1); + size_t end = s.find_last_not_of(delimiters); + if (end == std::string::npos) { + return ""; // Return empty string if all characters are delimiters + } + return s.substr(0, end + 1); } static inline std::string trim_left_copy(const std::string &s, const std::string &delimiters) { - return s.substr(s.find_first_not_of(delimiters)); + size_t start = s.find_first_not_of(delimiters); + if (start == std::string::npos) { + return ""; // Return empty string if all characters are delimiters + } + return s.substr(start); } std::string Utils::trim_copy(const std::string &s, const std::string &delimiters) {