[#2659] Make URL hook handle multiple $_GET arguments

This commit is contained in:
Emmanuel Milou
2010-01-15 15:40:53 -05:00
parent 31de0e94f9
commit 631833fe7e
2 changed files with 27 additions and 2 deletions

View File

@ -19,6 +19,7 @@
#include "urlhook.h"
#include <iostream>
#include <vector>
UrlHook::UrlHook () { }
@ -28,9 +29,33 @@ int UrlHook::addAction (std::string field_value, std::string command)
{
std::string command_bg;
std::string temp;
std::vector <std::string> args;
size_t pos;
unsigned int i;
/* Escape the '&' char to not discard $_GET parameters in the URL - #2659 */
while ( (pos = field_value.find ("&", 0)) != std::string::npos) {
temp = field_value.substr (0, pos);
field_value.erase (0, pos + 1);
args.push_back (temp);
std::cout << temp << " " << std::endl;
}
command_bg = command + " ";
pos = args.size ();
for (i=0; i<pos; i++) {
// Escape the "&"
command_bg += args[i] + "\\&";
}
// Retrieve the last argument
command_bg += field_value;
/* Execute the command in the background to not block the application */
command_bg = command + " " + field_value + "&" ;
command_bg += "&";
/* Execute a system call */
return RUN_COMMAND (command_bg.c_str());

View File

@ -38,7 +38,7 @@ void HookManagerTest::testAddAction ()
int status;
status = urlhook->addAction ("www.google.ca", "x-www-browser");
status = urlhook->addAction ("http://www.google.ca/?arg1=arg1&arg2=nvls&x=2&y=45&z=1", "x-www-browser");
CPPUNIT_ASSERT (status == 0);
}