mirror of
https://github.com/valitydev/yamerl.git
synced 2024-11-06 02:45:23 +00:00
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:
parent
e4f205ad8e
commit
7026adbd85
@ -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) ->
|
||||
|
2
testsuite/data/parsing/block_mapping_noeol.data
Normal file
2
testsuite/data/parsing/block_mapping_noeol.data
Normal file
@ -0,0 +1,2 @@
|
||||
# vim:binary:noeol:
|
||||
key:
|
62
testsuite/data/parsing/block_mapping_noeol.pattern
Normal file
62
testsuite/data/parsing/block_mapping_noeol.pattern
Normal 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}])
|
||||
)
|
Loading…
Reference in New Issue
Block a user