Skip to content

Commit 98fa1f7

Browse files
authored
Merge pull request #4 from thomas9911/fix/empty-string-in-combine-backend
fix: allow for empty strings with combine backend
2 parents a8465c8 + 6819cda commit 98fa1f7

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

lib/json5/decode/backend/combine/string.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defmodule Json5.Decode.Backend.Combine.String do
1515

1616
defp json5_single_string_characters(prev \\ nil) do
1717
prev
18-
|> many1(json5_single_string_character())
18+
|> many(json5_single_string_character())
1919
|> map(&:erlang.iolist_to_binary/1)
2020
end
2121

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

2626
defp json5_double_string_characters(prev \\ nil) do
2727
prev
28-
|> many1(json5_double_string_character())
28+
|> many(json5_double_string_character())
2929
|> map(&:erlang.iolist_to_binary/1)
3030
end
3131

mix.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Json5.MixProject do
44
def project do
55
[
66
app: :json5,
7-
version: "0.3.0",
7+
version: "0.3.1",
88
elixir: "~> 1.10",
99
description: "Json5 in Elixir",
1010
start_permanent: Mix.env() == :prod,
@@ -16,6 +16,7 @@ defmodule Json5.MixProject do
1616
"coveralls.post": :test,
1717
"coveralls.html": :test
1818
],
19+
compilers: [:yecc, :leex] ++ Mix.compilers(),
1920
package: package(),
2021
source_url: "https://github.com/thomas9911/json5"
2122
]

test/json5/decode_test.exs

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ defmodule Json5.DecodeTest do
1818
[:boolean, true, "true"],
1919
["string single quote", "some text", "'some text'"],
2020
["string double quote", "some text", "\"some text\""],
21+
["empty string single quote", "", "''"],
22+
["empty string double quote", "", "\"\""],
2123
["string unicode", "ūňĭčŏďē text", "\"ūňĭčŏďē text\""],
2224
["number hex", decimal(2801), "0xaf1"],
2325
["number hex", decimal(120_772), "0X1D7c4"],
@@ -47,7 +49,7 @@ defmodule Json5.DecodeTest do
4749
4850
[
4951
50-
null, 2,
52+
null, 2,
5153
5254
'some text']
5355
@@ -75,7 +77,7 @@ defmodule Json5.DecodeTest do
7577
:comment,
7678
[decimal(1), decimal(2)],
7779
"""
78-
[1,
80+
[1,
7981
// wauw comment
8082
2]
8183
"""
@@ -84,7 +86,7 @@ defmodule Json5.DecodeTest do
8486
:multi_line_comment,
8587
[decimal(1), decimal(2)],
8688
"""
87-
[1,
89+
[1,
8890
/*
8991
9092
just some text
@@ -131,7 +133,7 @@ defmodule Json5.DecodeTest do
131133
}),
132134
"""
133135
{
134-
test: 1,
136+
test: 1,
135137
'text': null,
136138
"nested": {
137139
other: 123,

test/test_helper.exs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
opts = if System.otp_release |> String.to_integer() |> Kernel.>=(26) do
2-
# formatting of maps changed in OTP 26,
3-
# so for now just test the lower versions in doctest.
4-
# the unittest do check both formats
5-
[exclude: [:doctest]]
6-
else
7-
[]
8-
end
1+
opts =
2+
if System.otp_release() |> String.to_integer() |> Kernel.>=(26) do
3+
# formatting of maps changed in OTP 26,
4+
# so for now just test the lower versions in doctest.
5+
# the unittest do check both formats
6+
[exclude: [:doctest]]
7+
else
8+
[]
9+
end
910

1011
ExUnit.start(opts)

0 commit comments

Comments
 (0)