Skip to content

Commit

Permalink
Merge pull request #4 from thomas9911/fix/empty-string-in-combine-bac…
Browse files Browse the repository at this point in the history
…kend

fix: allow for empty strings with combine backend
  • Loading branch information
thomas9911 authored Jun 17, 2024
2 parents a8465c8 + 6819cda commit 98fa1f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/json5/decode/backend/combine/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Json5.Decode.Backend.Combine.String do

defp json5_single_string_characters(prev \\ nil) do
prev
|> many1(json5_single_string_character())
|> many(json5_single_string_character())
|> map(&:erlang.iolist_to_binary/1)
end

Expand All @@ -25,7 +25,7 @@ defmodule Json5.Decode.Backend.Combine.String do

defp json5_double_string_characters(prev \\ nil) do
prev
|> many1(json5_double_string_character())
|> many(json5_double_string_character())
|> map(&:erlang.iolist_to_binary/1)
end

Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Json5.MixProject do
def project do
[
app: :json5,
version: "0.3.0",
version: "0.3.1",
elixir: "~> 1.10",
description: "Json5 in Elixir",
start_permanent: Mix.env() == :prod,
Expand All @@ -16,6 +16,7 @@ defmodule Json5.MixProject do
"coveralls.post": :test,
"coveralls.html": :test
],
compilers: [:yecc, :leex] ++ Mix.compilers(),
package: package(),
source_url: "https://github.com/thomas9911/json5"
]
Expand Down
10 changes: 6 additions & 4 deletions test/json5/decode_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ defmodule Json5.DecodeTest do
[:boolean, true, "true"],
["string single quote", "some text", "'some text'"],
["string double quote", "some text", "\"some text\""],
["empty string single quote", "", "''"],
["empty string double quote", "", "\"\""],
["string unicode", "ūňĭčŏďē text", "\"ūňĭčŏďē text\""],
["number hex", decimal(2801), "0xaf1"],
["number hex", decimal(120_772), "0X1D7c4"],
Expand Down Expand Up @@ -47,7 +49,7 @@ defmodule Json5.DecodeTest do
[
null, 2,
null, 2,
'some text']
Expand Down Expand Up @@ -75,7 +77,7 @@ defmodule Json5.DecodeTest do
:comment,
[decimal(1), decimal(2)],
"""
[1,
[1,
// wauw comment
2]
"""
Expand All @@ -84,7 +86,7 @@ defmodule Json5.DecodeTest do
:multi_line_comment,
[decimal(1), decimal(2)],
"""
[1,
[1,
/*
just some text
Expand Down Expand Up @@ -131,7 +133,7 @@ defmodule Json5.DecodeTest do
}),
"""
{
test: 1,
test: 1,
'text': null,
"nested": {
other: 123,
Expand Down
17 changes: 9 additions & 8 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
opts = if System.otp_release |> String.to_integer() |> Kernel.>=(26) do
# formatting of maps changed in OTP 26,
# so for now just test the lower versions in doctest.
# the unittest do check both formats
[exclude: [:doctest]]
else
[]
end
opts =
if System.otp_release() |> String.to_integer() |> Kernel.>=(26) do
# formatting of maps changed in OTP 26,
# so for now just test the lower versions in doctest.
# the unittest do check both formats
[exclude: [:doctest]]
else
[]
end

ExUnit.start(opts)

0 comments on commit 98fa1f7

Please sign in to comment.