diff options
-rw-r--r-- | src/gleam/uri.gleam | 17 | ||||
-rw-r--r-- | test/gleam/uri_test.gleam | 5 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index 58ffeba..1c2447b 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -81,7 +81,22 @@ external fn erl_parse_query(String) -> Dynamic = pub fn parse_query(query: String) -> Result(List(tuple(String, String)), Nil) { query |> erl_parse_query - |> dynamic.typed_list(dynamic.typed_tuple2(_, dynamic.string, dynamic.string)) + |> dynamic.typed_list( + dynamic.typed_tuple2( + _, + dynamic.string, + fn(raw) { + case dynamic.string(raw) { + Ok(value) -> Ok(value) + Error(_reason) -> case dynamic.bool(raw) { + Ok(True) -> Ok("") + // Note this error message will be niled at the end of this function. + _ -> Error("expected a boolean or string, got neither") + } + } + }, + ), + ) |> result.nil_error } diff --git a/test/gleam/uri_test.gleam b/test/gleam/uri_test.gleam index 2beeed5..ecefeec 100644 --- a/test/gleam/uri_test.gleam +++ b/test/gleam/uri_test.gleam @@ -72,6 +72,11 @@ pub fn parse_empty_query_string_test() { should.equal(parsed, []) } +pub fn parse_query_string_with_empty_test() { + uri.parse_query("present") + |> should.equal(Ok([tuple("present", "")])) +} + pub fn error_parsing_query_test() { should.equal(uri.parse_query("%C2"), Error(Nil)) } |