Browse Source

Permit binaries as proplist keys

Evan Miller 15 years ago
parent
commit
7242e9dff5
2 changed files with 11 additions and 1 deletions
  1. 9 1
      src/erlydtl/erlydtl_runtime.erl
  2. 2 0
      src/tests/erlydtl_unittests.erl

+ 9 - 1
src/erlydtl/erlydtl_runtime.erl

@@ -3,7 +3,15 @@
 -compile(export_all).
 
 find_value(Key, L) when is_list(L) ->
-    proplists:get_value(Key, L, proplists:get_value(atom_to_list(Key), L));
+    case proplists:get_value(Key, L) of
+        undefined ->
+            case proplists:get_value(atom_to_list(Key), L) of
+                undefined ->
+                    proplists:get_value(list_to_binary(atom_to_list(Key)), L);
+                Val -> Val
+            end;
+        Val -> Val
+    end;
 find_value(Key, {GBSize, GBData}) when is_integer(GBSize) ->
     case gb_trees:lookup(Key, {GBSize, GBData}) of
         {value, Val} ->

+ 2 - 0
src/tests/erlydtl_unittests.erl

@@ -60,6 +60,8 @@ tests() ->
                     <<"I enjoy {{ var1.game }}">>, [{var1, [{game, "Othello"}]}], <<"I enjoy Othello">>},
                 {"Render variable with string-key attribute",
                     <<"I also enjoy {{ var1.game }}">>, [{var1, [{"game", "Parcheesi"}]}], <<"I also enjoy Parcheesi">>},
+                {"Render variable with binary-key attribute",
+                    <<"I also enjoy {{ var1.game }}">>, [{var1, [{<<"game">>, "Parcheesi"}]}], <<"I also enjoy Parcheesi">>},
                 {"Render variable in dict",
                     <<"{{ var1 }}">>, dict:store(var1, "bar", dict:new()), <<"bar">>},
                 {"Render variable in gb_tree",