Browse Source

ctest: Don't modify build and site names

CTest currently removes non-filename characters from CTEST_SITE and
CTEST_BUILDNAME in an inconsistent way, which leads to unconnected
information on CDash.  Non-filename characters actually don't cause
any issue in CDash at all, nor are they invalid XML.  The only place
where removing them may be needed is when an actual filename is
constructed.

Remove the filtering from the SafeBuildIdField function and place
it where a filename is constructed.
Daniel Pfeifer 5 months ago
parent
commit
2aa2c9af97
2 changed files with 8 additions and 26 deletions
  1. 7 0
      Source/CTest/cmCTestSubmitHandler.cxx
  2. 1 26
      Source/cmCTest.cxx

+ 7 - 0
Source/CTest/cmCTestSubmitHandler.cxx

@@ -9,8 +9,10 @@
 
 #include <cm/iomanip>
 #include <cm/optional>
+#include <cm/string>
 #include <cm/string_view>
 #include <cmext/algorithm>
+#include <cmext/string_view>
 
 #include <cm3p/curl/curl.h>
 #include <cm3p/json/reader.h>
@@ -226,6 +228,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
       std::string remote_file =
         remoteprefix + cmSystemTools::GetFilenameName(file);
 
+      // Erase non-filename and non-space whitespace characters.
+      cm::erase_if(remote_file, [](char c) {
+        return cm::contains("\\:*?\"<>|\n\r\t\f\v"_s, c);
+      });
+
       *this->LogFile << "\tUpload file: " << local_file << " to "
                      << remote_file << std::endl;
 

+ 1 - 26
Source/cmCTest.cxx

@@ -1005,32 +1005,7 @@ bool cmCTest::RunMakeCommand(std::string const& command, std::string& output,
 
 std::string cmCTest::SafeBuildIdField(std::string const& value)
 {
-  std::string safevalue(value);
-
-  if (!safevalue.empty()) {
-    // Disallow non-filename and non-space whitespace characters.
-    // If they occur, replace them with ""
-    //
-    char const* disallowed = "\\:*?\"<>|\n\r\t\f\v";
-
-    if (safevalue.find_first_of(disallowed) != std::string::npos) {
-      std::string::size_type i = 0;
-      std::string::size_type n = strlen(disallowed);
-      char replace[2];
-      replace[1] = 0;
-
-      for (i = 0; i < n; ++i) {
-        replace[0] = disallowed[i];
-        cmSystemTools::ReplaceString(safevalue, replace, "");
-      }
-    }
-  }
-
-  if (safevalue.empty()) {
-    safevalue = "(empty)";
-  }
-
-  return safevalue;
+  return value.empty() ? "(empty)" : value;
 }
 
 void cmCTest::StartXML(cmXMLWriter& xml, cmake* cm, bool append)