Skip to content

Commit

Permalink
fixed small CGI bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 12, 2012
1 parent eeed95f commit eb1ff6d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

3.41 2012-09-12
- Fixed small CGI bug.

3.40 2012-09-11
- Improved tests.
- Fixed Perl 5.10.1 compatibility.
Expand Down
10 changes: 4 additions & 6 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -211,10 +211,9 @@ sub _parse_env {
my $url = $self->url;
my $base = $url->base;
while (my ($name, $value) = each %$env) {
next unless $name =~ /^HTTP_/i;
$name =~ s/^HTTP_//i;
next unless $name =~ s/^HTTP_//i;
$name =~ s/_/-/g;
$headers->header($name, $value);
$headers->header($name => $value);

# Host/Port
if ($name eq 'HOST') {
Expand Down Expand Up @@ -256,9 +255,8 @@ sub _parse_env {

# Remove SCRIPT_NAME prefix if necessary
my $buffer = $path->to_string;
$value =~ s!^/!!;
$value =~ s!/$!!;
$buffer =~ s!^/?$value/?!!;
$value =~ s!^/|/$!!g;
$buffer =~ s!^/?\Q$value\E/?!!;
$buffer =~ s!^/!!;
$path->parse($buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -38,7 +38,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.40';
our $VERSION = '3.41';

sub AUTOLOAD {
my $self = shift;
Expand Down
12 changes: 6 additions & 6 deletions t/mojo/request_cgi.t
Expand Up @@ -11,10 +11,10 @@ $req->content->on(body => sub { $body++ });
$req->parse(
HTTP_CONTENT_LENGTH => 11,
HTTP_EXPECT => '100-continue',
PATH_INFO => '/test/index.cgi/foo/bar',
PATH_INFO => '/te+st/index.cgi/foo/bar',
QUERY_STRING => 'lalala=23&bar=baz',
REQUEST_METHOD => 'POST',
SCRIPT_NAME => '/test/index.cgi',
SCRIPT_NAME => '/te+st/index.cgi',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
Expand All @@ -27,14 +27,14 @@ ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->headers->expect, '100-continue', 'right "Expect" value';
is $req->url->path, 'foo/bar', 'right path';
is $req->url->base->path, '/test/index.cgi/', 'right base path';
is $req->url->base->host, 'localhost', 'right base host';
is $req->url->base->port, 8080, 'right base port';
is $req->url->base->path, '/te+st/index.cgi/', 'right base path';
is $req->url->base->host, 'localhost', 'right base host';
is $req->url->base->port, 8080, 'right base port';
is $req->url->query, 'lalala=23&bar=baz', 'right query';
is $req->version, '1.0', 'right version';
is $req->body, 'Hello World', 'right content';
is $req->url->to_abs->to_string,
'http://localhost:8080/test/index.cgi/foo/bar?lalala=23&bar=baz',
'http://localhost:8080/te+st/index.cgi/foo/bar?lalala=23&bar=baz',
'right absolute URL';

# Parse Lighttpd like CGI environment variables and a body
Expand Down

0 comments on commit eb1ff6d

Please sign in to comment.