-rw-r--r-- | lib/consumer.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc index cbe0769..bb6358c 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -304,38 +304,45 @@ namespace opkele { | |||
304 | if(!server.empty()) | 304 | if(!server.empty()) |
305 | break; | 305 | break; |
306 | } | 306 | } |
307 | } | 307 | } |
308 | if(server.empty()) | 308 | if(server.empty()) |
309 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); | 309 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); |
310 | } | 310 | } |
311 | 311 | ||
312 | assoc_t consumer_t::find_assoc(const string& server) { | 312 | assoc_t consumer_t::find_assoc(const string& server) { |
313 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); | 313 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); |
314 | } | 314 | } |
315 | 315 | ||
316 | string consumer_t::canonicalize(const string& url) { | 316 | string consumer_t::canonicalize(const string& url) { |
317 | string rv = url; | 317 | string rv = url; |
318 | // strip leading and trailing spaces | 318 | // strip leading and trailing spaces |
319 | string::size_type i = rv.find_first_not_of(" \t\r\n"); | 319 | string::size_type i = rv.find_first_not_of(" \t\r\n"); |
320 | if(i==string::npos) | 320 | if(i==string::npos) |
321 | throw bad_input(OPKELE_CP_ "empty URL"); | 321 | throw bad_input(OPKELE_CP_ "empty URL"); |
322 | if(i) | 322 | if(i) |
323 | rv.erase(0,i); | 323 | rv.erase(0,i); |
324 | i = rv.find_last_not_of(" \t\r\n"); | 324 | i = rv.find_last_not_of(" \t\r\n"); |
325 | assert(i!=string::npos); | 325 | assert(i!=string::npos); |
326 | if(i<(rv.length()-1)) | 326 | if(i<(rv.length()-1)) |
327 | rv.erase(i+1); | 327 | rv.erase(i+1); |
328 | // add missing http:// | 328 | // add missing http:// |
329 | i = rv.find("://"); | 329 | i = rv.find("://"); |
330 | if(i==string::npos) { // primitive. but do we need more? | 330 | if(i==string::npos) { // primitive. but do we need more? |
331 | rv.insert(0,"http://"); | 331 | rv.insert(0,"http://"); |
332 | i = sizeof("http://")-1; | 332 | i = sizeof("http://")-1; |
333 | }else{ | 333 | }else{ |
334 | i += sizeof("://")-1; | 334 | i += sizeof("://")-1; |
335 | } | 335 | } |
336 | if(rv.find('/',i)==string::npos) | 336 | string::size_type qm = rv.find('?',i); |
337 | rv += '/'; | 337 | string::size_type sl = rv.find('/',i); |
338 | if(qm!=string::npos) { | ||
339 | if(sl==string::npos || sl>qm) | ||
340 | rv.insert(qm,1,'/'); | ||
341 | }else{ | ||
342 | if(sl==string::npos) | ||
343 | rv += '/'; | ||
344 | } | ||
338 | return rv; | 345 | return rv; |
339 | } | 346 | } |
340 | 347 | ||
341 | } | 348 | } |