Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Slight improvement to error detection during parsing.

  • Loading branch information...
commit ab955f4a50b95ed542d721cef9c9391abd3dbcaf 1 parent 5f1c8a7
@tonyg authored
View
2  doc/rfc4627_jsonrpc.html
@@ -249,7 +249,7 @@ <h3 class="function"><a name="error_response-3">error_response/3</a></h3>
<h3 class="function"><a name="expand_jsonrpc_reply-2">expand_jsonrpc_reply/2</a></h3>
<div class="spec">
-<p><tt>expand_jsonrpc_reply() -&gt; term()</tt></p>
+<p><tt>expand_jsonrpc_reply(RequestId, X2) -&gt; any()</tt></p>
</div>
<h3 class="function"><a name="gen_object_name-0">gen_object_name/0</a></h3>
View
10 src/rfc4627.erl
@@ -349,6 +349,7 @@ parse("false" ++ Rest) -> {false, Rest};
parse("null" ++ Rest) -> {null, Rest};
parse([${ | Rest]) -> parse_object(skipws(Rest), []);
parse([$[ | Rest]) -> parse_array(skipws(Rest), []);
+parse([]) -> exit(unexpected_end_of_input);
parse(Chars) -> parse_number(Chars, []).
skipws([X | Rest]) when X =< 32 ->
@@ -440,12 +441,13 @@ finish_number(Acc, Rest) ->
Value -> Value
end, Rest}.
-parse_number([], _Acc) ->
- exit(syntax_error);
parse_number([$- | Rest], Acc) ->
parse_number1(Rest, [$- | Acc]);
-parse_number(Rest, Acc) ->
- parse_number1(Rest, Acc).
+parse_number(Rest = [C | _], Acc) ->
+ case is_digit(C) of
+ true -> parse_number1(Rest, Acc);
+ false -> exit(syntax_error)
+ end.
parse_number1(Rest, Acc) ->
{Acc1, Rest1} = parse_int_part(Rest, Acc),
View
6 test/test_rfc4627.erl
@@ -36,6 +36,7 @@ test_all() ->
passed = test_records(),
passed = test_unicode(),
passed = test_equiv(),
+ passed = test_eof_detection(),
passed.
test_codec() ->
@@ -167,3 +168,8 @@ test_equiv() ->
true = rfc4627:equiv(<<>>, <<>>),
passed.
+
+test_eof_detection() ->
+ {error, unexpected_end_of_input} = rfc4627:decode(""),
+ {error, syntax_error} = rfc4627:decode("()"),
+ passed.
Please sign in to comment.
Something went wrong with that request. Please try again.