diff --git a/src/command.cpp b/src/command.cpp index 2a557764c5..29c1289b9c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1180,7 +1180,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32_t p1, uint32_t p2, uint64_ std::vector buffer; CommandSerialisationBuffer serialiser(buffer, SHRT_MAX); aux_data->Serialise(serialiser); - aux_str = FormatArrayAsHex(buffer); + aux_str = FormatArrayAsHex(buffer, false); } std::string text_buf; if (text != nullptr) { diff --git a/src/network/network.cpp b/src/network/network.cpp index 7ad6d6a8d4..fd4f191d35 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -219,7 +219,7 @@ std::string GenerateCompanyPasswordHash(const std::string &password, const std:: checksum.Append(salted_password_string.data(), salted_password_string.size()); checksum.Finish(digest); - return FormatArrayAsHex(digest); + return FormatArrayAsHex(digest, false); } /** @@ -1375,7 +1375,7 @@ std::string NetworkGenerateRandomKeyString(uint bytes) uint8_t *key = AllocaM(uint8_t, bytes); RandomBytesWithFallback({ key, bytes }); - return FormatArrayAsHex({key, bytes}); + return FormatArrayAsHex({key, bytes}, false); } /** This tries to launch the network for a given OS */ diff --git a/src/string_func.h b/src/string_func.h index edb27d8f00..87522c0eb7 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -41,7 +41,7 @@ int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap) std::string CDECL stdstr_fmt(const char *str, ...) WARN_FORMAT(1, 2); std::string stdstr_vfmt(const char *str, va_list va) WARN_FORMAT(1, 0); -std::string FormatArrayAsHex(std::span data, bool upper_case = false); +std::string FormatArrayAsHex(std::span data, bool upper_case = true); char *StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK) NOACCESS(2); [[nodiscard]] std::string StrMakeValid(std::string_view str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK); diff --git a/src/tests/string_func.cpp b/src/tests/string_func.cpp index e0ea052cbc..a5cd29100d 100644 --- a/src/tests/string_func.cpp +++ b/src/tests/string_func.cpp @@ -341,7 +341,9 @@ TEST_CASE("FormatArrayAsHex") { CHECK(FormatArrayAsHex(std::array{}) == ""); CHECK(FormatArrayAsHex(std::array{0x12}) == "12"); - CHECK(FormatArrayAsHex(std::array{0x13, 0x38, 0x42, 0xAF}) == "133842af"); + CHECK(FormatArrayAsHex(std::array{0x13, 0x38, 0x42, 0xAF}) == "133842AF"); + CHECK(FormatArrayAsHex(std::array{0x13, 0x38, 0x42, 0xAF}, true) == "133842AF"); + CHECK(FormatArrayAsHex(std::array{0x13, 0x38, 0x42, 0xAF}, false) == "133842af"); } TEST_CASE("ConvertHexToBytes")