-
-
Save anonymous/6cb0ed7ad64c91c05facd6f49a41df53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/UserAgent.pm b/lib/Mojo/UserAgent.pm | |
index ebe9537..692d2f2 100644 | |
--- a/lib/Mojo/UserAgent.pm | |
+++ b/lib/Mojo/UserAgent.pm | |
@@ -3,6 +3,7 @@ use Mojo::Base 'Mojo::EventEmitter'; | |
# "Fry: Since when is the Internet about robbing people of their privacy? | |
# Bender: August 6, 1991." | |
+use Carp 'croak'; | |
use Mojo::IOLoop; | |
use Mojo::Util qw(monkey_patch term_escape); | |
use Mojo::UserAgent::CookieJar; | |
@@ -48,6 +49,10 @@ sub start { | |
# Fork-safety | |
$self->_cleanup->server->restart unless ($self->{pid} //= $$) eq $$; | |
+ my $proto = $tx->req->url->protocol; | |
+ croak qq/Unsupported protocol "$proto"/ | |
+ if $proto && $proto ne 'http' && $proto ne 'https'; | |
+ | |
# Non-blocking | |
if ($cb) { | |
warn "-- Non-blocking request (@{[_url($tx)]})\n" if DEBUG; | |
diff --git a/t/mojo/user_agent.t b/t/mojo/user_agent.t | |
index de5e604..99ce618 100644 | |
--- a/t/mojo/user_agent.t | |
+++ b/t/mojo/user_agent.t | |
@@ -592,4 +592,8 @@ Mojo::IOLoop->delay( | |
)->wait; | |
is scalar @$result, 2, 'two active connections'; | |
+# Unsupported protocol | |
+eval { $ua->get('file:///etc/passwd') }; | |
+like $@, qr/Unsupported protocol "file"/, 'right error'; | |
+ | |
done_testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment