Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit ba9b230

Browse files
committed
fix(editor): utils
keys_to_atoms edge case
1 parent b255880 commit ba9b230

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/helper/utils.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ defmodule Helper.Utils do
102102
Map.new(json, &reduce_keys_to_atoms/1)
103103
end
104104

105+
def keys_to_atoms(string) when is_binary(string), do: string
106+
105107
def reduce_keys_to_atoms({key, val}) when is_map(val),
106108
do: {String.to_existing_atom(key), keys_to_atoms(val)}
107109

test/helper/utils_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ defmodule GroupherServer.Test.Helper.UtilsTest do
2626
describe "map keys to atom" do
2727
test "string keys should covert to atom keys on nested map" do
2828
atom_map = %{
29+
string_array: [
30+
"line 1",
31+
"line 2",
32+
"line 3"
33+
],
2934
blocks: [
3035
%{
3136
data: %{
@@ -56,6 +61,11 @@ defmodule GroupherServer.Test.Helper.UtilsTest do
5661
_ = :labelType
5762

5863
string_map = %{
64+
"string_array" => [
65+
"line 1",
66+
"line 2",
67+
"line 3"
68+
],
5969
"blocks" => [
6070
%{
6171
"data" => %{

0 commit comments

Comments
 (0)