Skip to content

Commit

Permalink
Fix parsing of URLs containing IPv6 addresses
Browse files Browse the repository at this point in the history
That includes the front-end accepting things like ``[::1]`` and the injector
accepting URLs like ``http://[2001:db8::1]:8080/foo/bar``.
  • Loading branch information
ivilata committed Jun 19, 2018
1 parent fc23b90 commit e17d14a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/client_front_end.cpp
Expand Up @@ -64,7 +64,7 @@ static ostream& operator<<(ostream& os, const ClientFrontEnd::Task& task) {
static
string path_from_url(const string& url) {
// This is not a bullet-proof URL parser, it just gets some common cases here.
static const boost::regex urlrx("^(?:http://[-\\.a-z0-9]+)?(/[^?#]*).*");

This comment has been minimized.

Copy link
@inetic

inetic Jun 20, 2018

Member

@ivilata could you try std::regex instead whenever you'll be writing new regex code?

This comment has been minimized.

Copy link
@ivilata

ivilata Jun 20, 2018

Author Collaborator

Didn't know it was already part of the Standard! Sure will do, probably after this is merged.

static const boost::regex urlrx("^(?:http://[-\\.:\\[\\]a-z0-9]+)?(/[^?#]*).*");
boost::smatch url_match;
boost::regex_match(url, url_match, urlrx);
return url_match[1];
Expand Down
2 changes: 1 addition & 1 deletion src/injector.cpp
Expand Up @@ -132,7 +132,7 @@ struct InjectorCacheControl {

// Parse the URL to tell HTTP/HTTPS, host, port.
auto target = rq.target().to_string();
static const boost::regex urlrx("^(http|https)://([-\\.a-z0-9]+)(:[0-9]{1,5})?/.*");
static const boost::regex urlrx("^(http|https)://([-\\.a-z0-9]+|\\[[:0-9a-fA-F]+\\])(:[0-9]{1,5})?/.*");
boost::smatch url_match;
if (!boost::regex_match(target, url_match, urlrx)) {
ec = asio::error::operation_not_supported; // unsupported URL
Expand Down

0 comments on commit e17d14a

Please sign in to comment.