+ fix fulltext result page for pattern including mustbeurlencoded characters

pull/9/head
kelson42 14 years ago
parent a977b0ca67
commit 8f85669e53

@ -86,46 +86,6 @@ static pthread_mutex_t compressorLock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t resourceLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t resourceLock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t verboseFlagLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t verboseFlagLock = PTHREAD_MUTEX_INITIALIZER;
// Urlencode
//based on javascript encodeURIComponent()
string char2hex( char dec )
{
char dig1 = (dec&0xF0)>>4;
char dig2 = (dec&0x0F);
if ( 0<= dig1 && dig1<= 9) dig1+=48; //0,48inascii
if (10<= dig1 && dig1<=15) dig1+=97-10; //a,97inascii
if ( 0<= dig2 && dig2<= 9) dig2+=48;
if (10<= dig2 && dig2<=15) dig2+=97-10;
string r;
r.append( &dig1, 1);
r.append( &dig2, 1);
return r;
}
string urlEncode(const string &c) {
string escaped="";
int max = c.length();
for(int i=0; i<max; i++)
{
if ( (48 <= c[i] && c[i] <= 57) ||//0-9
(65 <= c[i] && c[i] <= 90) ||//abc...xyz
(97 <= c[i] && c[i] <= 122) || //ABC...XYZ
(c[i]=='~' || c[i]=='!' || c[i]=='*' || c[i]=='(' || c[i]==')' || c[i]=='\'')
)
{
escaped.append( &c[i], 1);
}
else
{
escaped.append("%");
escaped.append( char2hex(c[i]) );//converts char 255 to string "ff"
}
}
return escaped;
}
void introduceTaskbar(string &content, const string &humanReadableBookId) { void introduceTaskbar(string &content, const string &humanReadableBookId) {
pthread_mutex_lock(&resourceLock); pthread_mutex_lock(&resourceLock);
content = appendToFirstOccurence(content, "<head>", getResourceAsString("jqueryui/include.html.part")); content = appendToFirstOccurence(content, "<head>", getResourceAsString("jqueryui/include.html.part"));
@ -255,12 +215,13 @@ static int accessHandlerCallback(void *cls,
const char* pattern = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "pattern"); const char* pattern = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "pattern");
if (pattern == NULL) if (pattern == NULL)
pattern = ""; pattern = "";
std::string patternString = kiwix::urlDecode(string(pattern));
/* Try first to load directly the article if exactly matching the pattern */ /* Try first to load directly the article if exactly matching the pattern */
std::string patternCorrespondingUrl; std::string patternCorrespondingUrl;
if (reader != NULL) { if (reader != NULL) {
pthread_mutex_lock(&readerLock); pthread_mutex_lock(&readerLock);
reader->getPageUrlFromTitle(pattern, patternCorrespondingUrl); reader->getPageUrlFromTitle(patternString, patternCorrespondingUrl);
pthread_mutex_unlock(&readerLock); pthread_mutex_unlock(&readerLock);
if (!patternCorrespondingUrl.empty()) { if (!patternCorrespondingUrl.empty()) {
httpRedirection="/" + humanReadableBookId + "/" + patternCorrespondingUrl; httpRedirection="/" + humanReadableBookId + "/" + patternCorrespondingUrl;
@ -283,7 +244,6 @@ static int accessHandlerCallback(void *cls,
/* Get the results */ /* Get the results */
pthread_mutex_lock(&searcherLock); pthread_mutex_lock(&searcherLock);
try { try {
std::string patternString = string(pattern);
searcher->search(patternString, startNumber, endNumber, isVerbose()); searcher->search(patternString, startNumber, endNumber, isVerbose());
content = searcher->getHtml(); content = searcher->getHtml();
} catch (const std::exception& e) { } catch (const std::exception& e) {
@ -293,7 +253,7 @@ static int accessHandlerCallback(void *cls,
mimeType = "text/html; charset=utf-8"; mimeType = "text/html; charset=utf-8";
} else { } else {
content = "<html><head><title>Fulltext search unavailable</title></head><body><h1>Not Found</h1><p>There is no article with the title <b>\"" + string(pattern) + "\"</b> and the fulltext search engine is not available for this content.</p></body></html>"; content = "<html><head><title>Fulltext search unavailable</title></head><body><h1>Not Found</h1><p>There is no article with the title <b>\"" + patternString + "\"</b> and the fulltext search engine is not available for this content.</p></body></html>";
mimeType = "text/html"; mimeType = "text/html";
httpResponseCode = MHD_HTTP_NOT_FOUND; httpResponseCode = MHD_HTTP_NOT_FOUND;
} }

@ -115,13 +115,13 @@
<div class="footer"> <div class="footer">
<ul> <ul>
<TMPL_if (resultLastPageStart>0)> <TMPL_if (resultLastPageStart>0)>
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPattern>&start=0&end=<TMPL_var resultRange>">◀</a></li> <li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=0&end=<TMPL_var resultRange>">◀</a></li>
</TMPL_if> </TMPL_if>
<TMPL_loop pages> <TMPL_loop pages>
<li><a <TMPL_if selected>class="selected"</TMPL_if> href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPattern>&start=<TMPL_var start>&end=<TMPL_var end>"><TMPL_var label></a></li> <li><a <TMPL_if selected>class="selected"</TMPL_if> href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var start>&end=<TMPL_var end>"><TMPL_var label></a></li>
</TMPL_LOOP> </TMPL_LOOP>
<TMPL_if (resultLastPageStart>0)> <TMPL_if (resultLastPageStart>0)>
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPattern>&start=<TMPL_var resultLastPageStart>&end=<TMPL_var (resultLastPageStart+resultRange)>">▶</a></li> <li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var resultLastPageStart>&end=<TMPL_var (resultLastPageStart+resultRange)>">▶</a></li>
</TMPL_if> </TMPL_if>
</ul> </ul>
</div> </div>

Loading…
Cancel
Save