Skip to content

Commit

Permalink
WebPositive: Search engine string now gets encoded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tri-Edge AI authored and mmuman committed Dec 15, 2012
1 parent 6084a1e commit 69eca70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/apps/webpositive/BrowserWindow.cpp
Expand Up @@ -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)
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/apps/webpositive/BrowserWindow.h
Expand Up @@ -191,6 +191,7 @@ class BrowserWindow : public BWebWindow {

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);
Expand Down

0 comments on commit 69eca70

Please sign in to comment.