From c9337e0a62de11ae35b1c4917a2f390ea880fe32 Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Tue, 1 Jun 2021 02:13:52 +0200 Subject: [PATCH] Fix #4336 - Encode searchTerm in BCL (including spaces, not only "+" signs) cf https://microsoft.github.io/cpprestsdk/classweb_1_1uri.html#ac1a92ee41ad0e77e262a8b4fcb235ac1 --- src/utilities/bcl/RemoteBCL.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/utilities/bcl/RemoteBCL.cpp b/src/utilities/bcl/RemoteBCL.cpp index b6f9cac8411..a3b2d5460fd 100644 --- a/src/utilities/bcl/RemoteBCL.cpp +++ b/src/utilities/bcl/RemoteBCL.cpp @@ -639,8 +639,9 @@ bool RemoteBCL::startComponentLibraryMetaSearch(const std::string& searchTerm, c auto client = getClient(remoteUrl(), m_timeOutSeconds); web::uri_builder builder(U("/api/metasearch/")); - auto query = searchTerm.empty() ? "*" : searchTerm; - query = std::regex_replace(query, std::regex("\\+"), "%2B"); + // web::uri::encode_data_string will Encodes a string by converting all characters + // except for RFC 3986 unreserved characters to their hexadecimal representation. (eg: '+' => %2B, ' ' => %20) + auto query = searchTerm.empty() ? "*" : web::uri::encode_data_string(searchTerm); builder.append_path(to_string_t(query + ".xml")); builder.append_query(U("fq[]"), to_string_t("bundle:" + filterType)); @@ -685,8 +686,7 @@ bool RemoteBCL::startComponentLibraryMetaSearch(const std::string& searchTerm, c auto client = getClient(remoteUrl(), m_timeOutSeconds); web::uri_builder builder(U("/api/metasearch/")); - auto query = searchTerm.empty() ? "*" : searchTerm; - query = std::regex_replace(query, std::regex("\\+"), "%2B"); + auto query = searchTerm.empty() ? "*" : web::uri::encode_data_string(searchTerm); builder.append_path(to_string_t(query + ".xml")); builder.append_query(U("fq[]"), to_string_t("bundle:" + filterType)); @@ -731,8 +731,7 @@ bool RemoteBCL::startComponentLibrarySearch(const std::string& searchTerm, const auto client = getClient(remoteUrl(), m_timeOutSeconds); web::uri_builder builder(U("/api/search/")); - auto query = searchTerm.empty() ? "*" : searchTerm; - query = std::regex_replace(query, std::regex("\\+"), "%2B"); + auto query = searchTerm.empty() ? "*" : web::uri::encode_data_string(searchTerm); builder.append_path(to_string_t(query + ".xml")); builder.append_query(U("fq[]"), to_string_t("bundle:" + filterType)); @@ -774,8 +773,7 @@ bool RemoteBCL::startComponentLibrarySearch(const std::string& searchTerm, const auto client = getClient(remoteUrl(), m_timeOutSeconds); web::uri_builder builder(U("/api/search/")); - auto query = searchTerm.empty() ? "*" : searchTerm; - query = std::regex_replace(query, std::regex("\\+"), "%2B"); + auto query = searchTerm.empty() ? "*" : web::uri::encode_data_string(searchTerm); builder.append_path(to_string_t(query + ".xml")); builder.append_query(U("fq[]"), to_string_t("bundle:" + filterType));