WebPositive: Search engine string now gets encoded.

This commit is contained in:
Tri-Edge AI 2012-12-14 20:09:23 +02:00 committed by François Revol
parent 6084a1e1a4
commit 69eca70155
2 changed files with 24 additions and 2 deletions

View File

@ -2147,6 +2147,25 @@ BrowserWindow::_NewTabURL(bool isNewWindow) const
return url;
}
BString
BrowserWindow::_EncodeURIComponent(const BString& search)
{
const BString escCharList = " $&`:<>[]{}\"+#%@/;=?\\^|~\',";
BString result = search;
char hexcode[4];
for (int32 i = 0; i < result.Length(); i++) {
if (escCharList.FindFirst(result[i]) != B_ERROR) {
sprintf(hexcode, "%02X", (unsigned int)result[i]);
result[i] = '%';
result.Insert(hexcode, i + 1);
i += 2;
}
}
return result;
}
void
BrowserWindow::_VisitURL(const BString& url)
@ -2163,8 +2182,10 @@ BrowserWindow::_VisitSearchEngine(const BString& search)
// engine modifiable from Settings? :)
BString engine = "http://www.google.com/search?q=";
engine += search;
// WebKit takes care of URL encoding here.
engine += _EncodeURIComponent(search);
// We have to take care of some of the escaping before
// we hand over the string to WebKit, if we want queries
// like "4+3" to not be searched as "4 3".
_VisitURL(engine);
}

View File

@ -191,6 +191,7 @@ private:
BString _NewTabURL(bool isNewWindow) const;
BString _EncodeURIComponent(const BString& search);
void _VisitURL(const BString& url);
void _VisitSearchEngine(const BString& search);
inline bool _IsValidDomainChar(char ch);