From 8397a0d837d51bd04a8eb2d9fb12182224439a37 Mon Sep 17 00:00:00 2001 From: Khaled Mohamed Elborey <37024839+khalidelboray@users.noreply.github.com> Date: Sat, 10 Aug 2019 04:42:41 +0200 Subject: [PATCH] False and numbers support Passing False or any digits will cause a failure in `build-query-string` --- lib/PostCocoon/Url.pm6 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/PostCocoon/Url.pm6 b/lib/PostCocoon/Url.pm6 index 33da66a..8fb08c3 100644 --- a/lib/PostCocoon/Url.pm6 +++ b/lib/PostCocoon/Url.pm6 @@ -53,15 +53,19 @@ sub url-decode (Str $data --> Str) is export { multi sub build-query-string (Hash $hash --> Str) is export { my @query-items; for $hash.kv -> $key, $value { - if ($value eq True) { - @query-items.push: url-encode($key); - } elsif ($value ~~ List) { - for $value.kv -> $k, $v { - @query-items.push: url-encode($key) ~ "=" ~ url-encode($v); + given $value { + when Bool { + @query-items.push: url-encode($key) if $value; + } + when List { + for $value.kv -> $k, $v { + @query-items.push: url-encode($key) ~ "=" ~ url-encode(~$v); + } + } + default { + @query-items.push: url-encode($key) ~ "=" ~ url-encode(~$value); + } } - } else { - @query-items.push: url-encode($key) ~ "=" ~ url-encode($value); - } } return @query-items.join("&");