Skip to content

Commit

Permalink
normalize search query in help page
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey authored and jmcphers committed Oct 23, 2018
1 parent 8c86ec5 commit d63cc46
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/cpp/session/modules/SessionHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ bool isLocalURL(const std::string& url,
return false;
}

std::string normalizeHttpdSearchContent(const std::string& content)
{
return boost::regex_replace(
content,
boost::regex("(The search string was <b>\")(.*)(\"</b>)"),
[](const boost::smatch& m)
{
std::string query = m[2];
if (query.find('<') != std::string::npos)
query = string_utils::htmlEscape(query);

return m[1] + string_utils::htmlEscape(m[2]) + m[3];
});
}

template <typename F>
bool isHttpdErrorPayload(SEXP payloadSEXP, F accessor)
{
Expand Down Expand Up @@ -411,6 +426,10 @@ void handleHttpdResult(SEXP httpdSEXP,
content = r::sexp::asString(STRING_ELT(payloadSEXP, 0));
else if (TYPEOF(payloadSEXP) == VECSXP)
content = r::sexp::asString(VECTOR_ELT(payloadSEXP, 0));

// normalize search result output
if (boost::algorithm::iends_with(request.path(), "/search"))
content = normalizeHttpdSearchContent(content);

// check for special file returns
std::string fileName ;
Expand Down

0 comments on commit d63cc46

Please sign in to comment.