yamerl_parser: Fix an infinite loop with "key:"

The determine_token_type() function expected something after ':' to
distinguish a block mapping key from something else. And because it was
the end of the document, the parser tried again, leading to an infinite
loop.

Fixes #14.
This commit is contained in:
Jean-Sébastien Pédron 2016-10-30 00:30:33 +02:00
parent e4f205ad8e
commit 7026adbd85
No known key found for this signature in database
GPG Key ID: 39E99761A5FD94CC
3 changed files with 68 additions and 0 deletions

View File

@ -746,6 +746,10 @@ determine_token_type([$: | _] = Chars, Line, Col, Delta,
%% This is a key: value pair indicator only when the last token is
%% JSON-like and we're in flow context.
parse_mapping_value(Chars, Line, Col, Delta, Parser);
determine_token_type([$:] = Chars, Line, Col, Delta,
#yamerl_parser{raw_eos = true} = Parser)
when ?IN_BLOCK_CTX(Parser) ->
parse_mapping_value(Chars, Line, Col, Delta, Parser);
%% Anchor and alias indicator.
determine_token_type([$& | _] = Chars, Line, Col, Delta, Parser) ->

View File

@ -0,0 +1,2 @@
# vim:binary:noeol:
key:

View File

@ -0,0 +1,62 @@
%% vim:ft=erlang:
%% TEST
?_assertMatch(
{yamerl_parser,
{file,"${FILENAME}"},
[{io_blocksize, 1}],
<<>>,
24,
true,
[],
0,
25,
2,
5,
false,
2,
5,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
11,
10,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,2,5},
{yamerl_doc_end,2,5},
{yamerl_collection_end,2,5,block,mapping},
{yamerl_scalar,2,4,
{yamerl_tag,2,4,{non_specific,"?"}},
flow,plain,[]},
{yamerl_mapping_value,2,4},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"key"},
{yamerl_mapping_key,2,1},
{yamerl_collection_start,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,2,1,{1,2}, _},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file("${FILENAME}", [{io_blocksize, 1}])
)