Skip to content

Commit

Permalink
Fix Cldr.Json with charlist argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Aug 13, 2024
1 parent 2772c76 commit a5cd8de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

**Cldr Utils from version 2.27.0 requires Elixir 1.12 or later**

## Cldr Utils version 2.28.1

This is the changelog for Cldr Utils v2.28.1 released on August 14th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_utils/tags)

### Bug Fixes

* Fix `Cldr.Json.decode!/1` when calling with a charlist instead of a binary.

## Cldr Utils version 2.28.0

This is the changelog for Cldr Utils v2.28.0 released on July 10th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_utils/tags)
Expand Down
17 changes: 15 additions & 2 deletions lib/cldr/utils/json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ if Code.ensure_loaded?(:json) do
%{foo: 1}
"""
def decode!(string) do
def decode!(string) when is_binary(string) do
{json, :ok, ""} = :json.decode(string, :ok, %{null: nil})
json
end

def decode!(string, [keys: :atoms]) do
def decode!(charlist) when is_list(charlist) do
charlist
|> List.to_string()
|> decode!()
end

def decode!(string, [keys: :atoms]) when is_binary(string) do
push = fn key, value, acc ->
[{String.to_atom(key), value} | acc]
end
Expand All @@ -48,5 +54,12 @@ if Code.ensure_loaded?(:json) do
{json, :ok, ""} = :json.decode(string, :ok, decoders)
json
end

def decode!(charlist, options) when is_list(charlist) do
charlist
|> List.to_string()
|> decode!(options)
end

end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cldr.Utils.MixProject do
use Mix.Project

@version "2.28.0"
@version "2.28.1"
@source_url "https://github.com/elixir-cldr/cldr_utils"

def project do
Expand Down

0 comments on commit a5cd8de

Please sign in to comment.