morningman commented on code in PR #40567: URL: https://github.com/apache/doris/pull/40567#discussion_r1756234110
########## be/src/util/url_coding.cpp: ########## @@ -17,41 +17,17 @@ #include "util/url_coding.h" +#include <curl/curl.h> #include <libbase64.h> -#include <math.h> -#include <memory> #include <sstream> namespace doris { -static inline void url_encode(const char* in, int in_len, std::string* out) { - (*out).reserve(in_len); - std::stringstream ss; - - for (int i = 0; i < in_len; ++i) { - const char ch = in[i]; - - // Escape the character iff a) we are in Hive-compat mode and the - // character is in the Hive whitelist or b) we are not in - // Hive-compat mode, and the character is not alphanumeric or one - // of the four commonly excluded characters. - ss << ch; - } - - (*out) = ss.str(); -} - -void url_encode(const std::vector<uint8_t>& in, std::string* out) { - if (in.empty()) { - *out = ""; - } else { - url_encode(reinterpret_cast<const char*>(&in[0]), in.size(), out); - } -} - void url_encode(const std::string& in, std::string* out) { - url_encode(in.c_str(), in.size(), out); + auto* encoded_url = curl_easy_escape(nullptr, in.c_str(), static_cast<int>(in.length())); Review Comment: it may be failed and return null? https://curl.se/libcurl/c/curl_easy_escape.html need to handle it and return error ########## be/src/vec/functions/function_string.h: ########## @@ -2642,6 +2643,53 @@ class FunctionUrlDecode : public IFunction { } }; +class FunctionUrlEncode : public IFunction { +public: + static constexpr auto name = "url_encode"; + static FunctionPtr create() { return std::make_shared<FunctionUrlEncode>(); } + String get_name() const override { return name; } + size_t get_number_of_arguments() const override { return 1; } + bool is_variadic() const override { return false; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return std::make_shared<DataTypeString>(); + } + + Status execute_impl(FunctionContext* context, Block& block, + Review Comment: remove empty line -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org