Skip to content

Commit 9b4055e

Browse files
author
Sebastiano Merlino
committed
Adjusted in order to avoid errors in regex matching
1 parent 92690e4 commit 9b4055e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/http_endpoint.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ http_endpoint::http_endpoint(const string& url, bool family, bool registration):
4646
bool first = true;
4747
if(registration)
4848
{
49+
this->url_modded = "^/";
4950
for(unsigned int i = 0; i< parts.size(); i++)
5051
{
5152
if((parts[i] != "") && (parts[i][0] != '{'))
@@ -107,7 +108,8 @@ http_endpoint::http_endpoint(const string& url, bool family, bool registration):
107108
}
108109
this->url_pieces.push_back(parts[i]);
109110
}
110-
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE);
111+
this->url_modded += "$";
112+
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB);
111113
reg_compiled = true;
112114
}
113115
else
@@ -138,7 +140,7 @@ http_endpoint::http_endpoint(const http_endpoint& h):
138140
reg_compiled(h.reg_compiled)
139141
{
140142
if(this->reg_compiled)
141-
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE);
143+
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB);
142144
}
143145

144146
http_endpoint& http_endpoint::operator =(const http_endpoint& h)
@@ -148,7 +150,7 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h)
148150
this->family_url = h.family_url;
149151
this->reg_compiled = h.reg_compiled;
150152
if(this->reg_compiled)
151-
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE);
153+
regcomp(&(this->re_url_modded), url_modded.c_str(), REG_EXTENDED|REG_ICASE|REG_NOSUB);
152154
this->url_pars = h.url_pars;
153155
this->url_pieces = h.url_pieces;
154156
this->chunk_positions = h.chunk_positions;

test/Test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ http_response Test::render_GET(const http_request& r)
2323
cout << r.get_requestor_port() << endl;
2424
cout << "PROVA: " << r.get_arg("prova") << endl;
2525
cout << "ALTRO: " << r.get_arg("altro") << endl;
26+
cout << "THUMB: " << r.get_arg("thumbId") << endl;
2627
string pp = r.get_arg("prova");
2728
return http_file_response("/home/etr/progs/libhttpserver/test/readme", 200);
2829
}
@@ -59,7 +60,7 @@ int main()
5960
Test dt = Test();
6061
Test2 dt2 = Test2();
6162
ws.register_resource(string("base/{var1}/{var2}/drop_test/{var3}/tail"), &dt2, true);
62-
ws.register_resource(string("other/side"), &dt, true);
63+
ws.register_resource(string("other/side/{thumbId|[0-9]*}"), &dt, true);
6364
boost::thread* t1 = new boost::thread(boost::bind(&webserver::start, ws, true));
6465
t1->join();
6566
return 0;

0 commit comments

Comments
 (0)