]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix util::replace_all for string_view to non-C string (#1502)
authorhuangqinjin <huangqinjin@gmail.com>
Tue, 10 Sep 2024 17:46:42 +0000 (01:46 +0800)
committerGitHub <noreply@github.com>
Tue, 10 Sep 2024 17:46:42 +0000 (19:46 +0200)
src/ccache/util/string.cpp
unittest/test_util_string.cpp

index 111dac840cf0c135e3b98bbff83bf9305729c56b..cf4fd81eafc734f17a3ed085dd7c85cfe071eeef 100644 (file)
@@ -399,7 +399,7 @@ replace_all(const std::string_view string,
   while (left < string.size()) {
     size_t right = string.find(from, left);
     if (right == std::string_view::npos) {
-      result.append(string.data() + left);
+      result.append(string.data() + left, string.size() - left);
       break;
     }
     result.append(string.data() + left, right - left);
index 203fad6d559ad6059b67469e159bd65724e2d4e0..6714d93e0670b3505b7c39aa5b5e02f127c3f841 100644 (file)
@@ -494,6 +494,7 @@ TEST_CASE("util::replace_all")
   CHECK(util::replace_all("xabc", "abc", "defdef") == "xdefdef");
   CHECK(util::replace_all("abcx", "abc", "defdef") == "defdefx");
   CHECK(util::replace_all("xabcyabcz", "abc", "defdef") == "xdefdefydefdefz");
+  CHECK(util::replace_all(std::string_view("xaxbc", 4), "x", "y") == "yayb");
 }
 
 TEST_CASE("util::replace_first")