mirror of https://github.com/kiwix/libkiwix.git
Fixed handling of backslashes in suggestions
This commit is contained in:
parent
c727de6591
commit
4966f4155d
|
@ -333,6 +333,19 @@ std::string kiwix::render_template(const std::string& template_str, kainjow::mus
|
|||
namespace
|
||||
{
|
||||
|
||||
std::string escapeBackslashes(const std::string& s)
|
||||
{
|
||||
std::string es;
|
||||
es.reserve(s.size());
|
||||
for (char c : s) {
|
||||
if ( c == '\\' ) {
|
||||
es.push_back('\\');
|
||||
}
|
||||
es.push_back(c);
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
std::string makeFulltextSearchSuggestion(const std::string& lang,
|
||||
const std::string& queryString)
|
||||
{
|
||||
|
@ -358,10 +371,10 @@ void kiwix::Suggestions::add(const zim::SuggestionItem& suggestion)
|
|||
? suggestion.getSnippet()
|
||||
: suggestion.getTitle();
|
||||
|
||||
result.set("label", label);
|
||||
result.set("value", suggestion.getTitle());
|
||||
result.set("label", escapeBackslashes(label));
|
||||
result.set("value", escapeBackslashes(suggestion.getTitle()));
|
||||
result.set("kind", "path");
|
||||
result.set("path", suggestion.getPath());
|
||||
result.set("path", escapeBackslashes(suggestion.getPath()));
|
||||
result.set("first", m_data.is_empty_list());
|
||||
m_data.push_back(result);
|
||||
}
|
||||
|
@ -370,8 +383,9 @@ void kiwix::Suggestions::addFTSearchSuggestion(const std::string& uiLang,
|
|||
const std::string& queryString)
|
||||
{
|
||||
kainjow::mustache::data result;
|
||||
result.set("label", makeFulltextSearchSuggestion(uiLang, queryString));
|
||||
result.set("value", queryString + " ");
|
||||
const std::string label = makeFulltextSearchSuggestion(uiLang, queryString);
|
||||
result.set("label", escapeBackslashes(label));
|
||||
result.set("value", escapeBackslashes(queryString + " "));
|
||||
result.set("kind", "pattern");
|
||||
result.set("first", m_data.is_empty_list());
|
||||
m_data.push_back(result);
|
||||
|
|
Loading…
Reference in New Issue