Skip to content

Commit 356f1f6

Browse files
authored
Fix urlencoded + test (#61)
1 parent 3660216 commit 356f1f6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

META6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
"Test::Util::ServerPort",
4343
"Cro::HTTP::Client"
4444
],
45-
"version": "2.1.6"
45+
"version": "2.1.7"
4646
}

lib/Humming-Bird/Core.rakumod

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use Humming-Bird::HTTPServer;
99

1010
unit module Humming-Bird::Core;
1111

12-
our constant $VERSION = '2.1.5';
12+
our constant $VERSION = '2.1.7';
1313

1414
# Mime type parser from MIME::Types
1515
my constant $mime = MIME::Types.new;
@@ -99,7 +99,7 @@ class HTTPAction {
9999

100100
my sub parse-urlencoded(Str:D $urlencoded --> Map:D) {
101101
use URI::Encode;
102-
uri_decode_component($urlencoded).split('&', :skip-empty)>>.split('=', :skip-empty)>>.map(-> $a, $b { $b.contains(',') ?? slip $a => $b.split(',', :skip-empty) !! slip $a => $b }).flat.Map;
102+
uri_decode_component($urlencoded).split('&', :skip-empty)>>.split('=', 2, :skip-empty)>>.map(-> $a, $b { $b.contains(',') ?? slip $a => $b.split(',', :skip-empty) !! slip $a => $b }).flat.Map;
103103
}
104104

105105
class Request is HTTPAction is export {
@@ -120,7 +120,12 @@ class Request is HTTPAction is export {
120120
return $!content = Map.new unless self.header('Content-Type');
121121

122122
try {
123-
CATCH { default { warn "Failed trying to parse a body of type { self.header('Content-Type') }"; return ($!content = Map.new) } }
123+
CATCH {
124+
default {
125+
warn "Encountered Error: $_;\n\n Failed trying to parse a body of type { self.header('Content-Type') }"; return ($!content = Map.new)
126+
}
127+
}
128+
124129
if self.header('Content-Type').ends-with: 'json' {
125130
$!content = from-json(self.body).Map;
126131
} elsif self.header('Content-Type').ends-with: 'urlencoded' {

t/10-content-guessing.rakutest

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v6.d;
22
use Humming-Bird::Core;
33
use Test;
44

5-
plan 4;
5+
plan 5;
66

77
my $request = Request.new(body => '{ "foo": "bar" }', path => '/home', method => GET, version => 'HTTP/1.1');
88
$request.header('Content-Type', 'application/json');
@@ -22,4 +22,8 @@ $request.body = 'tom=abc&lob=123';
2222

2323
is $request.content<lob>, '123', 'Is urlencoded re-evaluated on change?';
2424

25+
$request.body = 'hyperlink=https%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3DxvFZjo5PgG0';
26+
27+
lives-ok sub { $request.content };
28+
2529
done-testing;

0 commit comments

Comments
 (0)