mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-29 07:10:50 -04:00
+ fix escaping problem by kiwix-serve suggestions
This commit is contained in:
parent
20771de512
commit
0f7c1d812d
@ -226,16 +226,19 @@ static int accessHandlerCallback(void *cls,
|
|||||||
content = "[";
|
content = "[";
|
||||||
reader->searchSuggestions(term, maxSuggestionCount);
|
reader->searchSuggestions(term, maxSuggestionCount);
|
||||||
while (reader->getNextSuggestion(suggestion)) {
|
while (reader->getNextSuggestion(suggestion)) {
|
||||||
|
kiwix::stringReplacement(suggestion, "\"", "\\\"");
|
||||||
content += (content == "[" ? "" : ",");
|
content += (content == "[" ? "" : ",");
|
||||||
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
||||||
suggestionCount++;
|
suggestionCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << suggestionCount << std::endl;
|
||||||
/* Try to get further suggestions with ucFirst(pattern) if maxSuggestionCount is not reached */
|
/* Try to get further suggestions with ucFirst(pattern) if maxSuggestionCount is not reached */
|
||||||
if (suggestionCount < 10) {
|
if (suggestionCount < 10) {
|
||||||
term = kiwix::ucFirst(term);
|
term = kiwix::ucFirst(term);
|
||||||
reader->searchSuggestions(term, maxSuggestionCount);
|
reader->searchSuggestions(term, maxSuggestionCount);
|
||||||
while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) {
|
while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) {
|
||||||
|
kiwix::stringReplacement(suggestion, "\"", "\\\"");
|
||||||
content += (content == "[" ? "" : ",");
|
content += (content == "[" ? "" : ",");
|
||||||
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
||||||
suggestionCount++;
|
suggestionCount++;
|
||||||
@ -246,7 +249,8 @@ static int accessHandlerCallback(void *cls,
|
|||||||
if (suggestionCount < 10) {
|
if (suggestionCount < 10) {
|
||||||
term = kiwix::lcFirst(term);
|
term = kiwix::lcFirst(term);
|
||||||
reader->searchSuggestions(term, maxSuggestionCount);
|
reader->searchSuggestions(term, maxSuggestionCount);
|
||||||
while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) {
|
while (reader->getNextSuggestion(suggestion) && suggestionCount < 10)
|
||||||
|
kiwix::stringReplacement(suggestion, "\"", "\\\"");
|
||||||
content += (content == "[" ? "" : ",");
|
content += (content == "[" ? "" : ",");
|
||||||
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
|
||||||
suggestionCount++;
|
suggestionCount++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user