Skip to content

Commit

Permalink
Fix explosion of empty lists in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
sirikid committed Aug 22, 2023
1 parent 22ee5b4 commit 9ad2e84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/yuri_template/query_expander.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ defmodule YuriTemplate.QueryExpander do
value = if is_map(value), do: Enum.to_list(value), else: value

case value do
[] ->
acc

[{k1, v1} | kvs] ->
Enum.reduce(
kvs,
Expand Down
7 changes: 7 additions & 0 deletions test/yuri_template/query_expander_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ defmodule YuriTemplate.QueryExpanderTest do
{"{?keys,who}", "?keys=semi,%3B,dot,.,comma,%2C&who=fred"},
{"{?list,half}", "?list=red,green,blue&half=50%25"}
]

test "empty keys explode" do
YuriTemplate.expand!(
"/category/{category_id}/{category_transliterate}/{page}{?specs*,per_page,sort,order}",
%{category_id: "1", category_transliterate: "x", page: "2", specs: []}
) == "/category/1/x/2"
end
end

0 comments on commit 9ad2e84

Please sign in to comment.