From d52681085e661e68bf7a0d56b013deada8d42385 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 2 Jun 2022 22:36:56 +0800 Subject: [PATCH] Fix String.http_escape on Windows (cherry picked from commit 1a7e3b3ab6da96a57a5aea59c52a7b6c015ba1b2) --- core/ustring.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index 5feec8fc860..da7432aa8ee 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3426,21 +3426,19 @@ String String::http_escape() const { const CharString temp = utf8(); String res; for (int i = 0; i < temp.length(); ++i) { - char ord = temp[i]; + uint8_t ord = temp[i]; if (ord == '.' || ord == '-' || ord == '_' || ord == '~' || (ord >= 'a' && ord <= 'z') || (ord >= 'A' && ord <= 'Z') || (ord >= '0' && ord <= '9')) { res += ord; } else { - char h_Val[3]; -#if defined(__GNUC__) || defined(_MSC_VER) - snprintf(h_Val, 3, "%02hhX", ord); -#else - sprintf(h_Val, "%02hhX", ord); -#endif - res += "%"; - res += h_Val; + char p[4] = { '%', 0, 0, 0 }; + static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + + p[1] = hex[ord >> 4]; + p[2] = hex[ord & 0xF]; + res += p; } } return res;