Skip to content

Commit

Permalink
Fix #4336 - Encode searchTerm in BCL (including spaces, not only "+" …
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Jun 1, 2021
1 parent 92a416c commit c9337e0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/utilities/bcl/RemoteBCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit c9337e0

Please sign in to comment.