From 0f7c1d812d8a104d12818e55220bffcc6b0bd3e1 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 15 Aug 2012 19:17:45 +0000 Subject: [PATCH] + fix escaping problem by kiwix-serve suggestions --- src/server/kiwix-serve.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 6e4480f..7670d57 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -226,16 +226,19 @@ static int accessHandlerCallback(void *cls, content = "["; reader->searchSuggestions(term, maxSuggestionCount); while (reader->getNextSuggestion(suggestion)) { + kiwix::stringReplacement(suggestion, "\"", "\\\""); content += (content == "[" ? "" : ","); content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}"; suggestionCount++; } + std::cout << suggestionCount << std::endl; /* Try to get further suggestions with ucFirst(pattern) if maxSuggestionCount is not reached */ if (suggestionCount < 10) { term = kiwix::ucFirst(term); reader->searchSuggestions(term, maxSuggestionCount); while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) { + kiwix::stringReplacement(suggestion, "\"", "\\\""); content += (content == "[" ? "" : ","); content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}"; suggestionCount++; @@ -246,7 +249,8 @@ static int accessHandlerCallback(void *cls, if (suggestionCount < 10) { term = kiwix::lcFirst(term); reader->searchSuggestions(term, maxSuggestionCount); - while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) { + while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) + kiwix::stringReplacement(suggestion, "\"", "\\\""); content += (content == "[" ? "" : ","); content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}"; suggestionCount++;