Skip to content

Commit

Permalink
fix parsing impartial negative numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
boudra committed Feb 9, 2019
1 parent 2fb2345 commit f689e61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions c_src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ void parse_number(decoder_t* d, json_event_t* e) {
return;
}

if(buf == limit) {
goto done;
}

if(*buf == '0' && buf + 1 < limit && is_digit(*(buf+1))) {
syntax_error(d, e);
return;
Expand Down
10 changes: 5 additions & 5 deletions test/stream_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule JaxonEventStreamTest do

@json_stream ~s(
{
"numbers": [1,2],
"numbers": [1,2,-1],
"empty_array": [],
"empty_object": {},
"bool1": true,
Expand Down Expand Up @@ -51,8 +51,8 @@ defmodule JaxonEventStreamTest do
assert [1] == query(stream, "$.numbers[0]")
assert [nil] == query(stream, "$.null")
assert [2] == query(stream, "$.numbers[1]")
assert [[1, 2]] == query(stream, "$.numbers")
assert [1, 2] == query(stream, "$.numbers[*]")
assert [[1, 2, -1]] == query(stream, "$.numbers")
assert [1, 2, -1] == query(stream, "$.numbers[*]")
assert ["Keanu Reeves"] == query(stream, "$.person.name")
assert [%{"name" => "The Matrix"}] == query(stream, "$.person.movies[1]")
assert ["Speed"] == query(stream, "$.person.movies[0].name")
Expand All @@ -68,7 +68,7 @@ defmodule JaxonEventStreamTest do
|> Elixir.Stream.take(30)
|> Enum.to_list()

assert Enum.take(Elixir.Stream.cycle([1, 2]), 30) == result
assert Enum.take(Elixir.Stream.cycle([1, 2, -1]), 30) == result
end

test "multiple JSON doucuments in a stream chunk" do
Expand All @@ -77,7 +77,7 @@ defmodule JaxonEventStreamTest do
|> Stream.query([:root, "numbers", :all])
|> Enum.to_list()

assert [1, 2, 1, 2] == result
assert [1, 2, -1, 1, 2, -1] == result
end

test "single values" do
Expand Down

0 comments on commit f689e61

Please sign in to comment.