# YAML Test Matrix

--- &test-NKF9
  Title: Empty keys in block and flow mapping
  Tags: [ empty-key, mapping ]

YAML

---
key: value
: empty key
---
{
 key: value, : empty key
}
---
# empty key and value
:
---
# empty key and value
{ : }

Expected Events

+STR
+DOC ---
+MAP
=VAL :key
=VAL :value
=VAL :
=VAL :empty key
-MAP
-DOC
+DOC ---
+MAP
=VAL :key
=VAL :value
=VAL :
=VAL :empty key
-MAP
-DOC
+DOC ---
+MAP
=VAL :
=VAL :
-MAP
-DOC
+DOC ---
+MAP
=VAL :
=VAL :
-MAP
-DOC
-STR

Expected JSON



c-libfyaml-event

 ok

cpp-yamlcpp-event

 ok

dotnet-yamldotnet-event

 ok

hs-hsyaml-event

 ok

nim-nimyaml-event

 ok

perl-pp-event

 ok

py-ruamel-event

 ok

js-yaml-event

 error
+STR
+DOC ---
+MAP
=VAL :key
=VAL :value
=VAL :
=VAL :empty key
-MAP
-DOC
+DOC ---
+MAP
=VAL :key
=VAL :value
=VAL :
=VAL :empty key
-MAP
-DOC
+DOC ---
+MAP
Error: Unexpected node type undefined

perl-syck-perl

 error
Syck parser (line 3, column 1): syntax error at /perl5/lib/perl5/x86_64-linux-thread-multi/YAML/Syck.pm line 60, <> line 1.

perl-yaml-perl

 error
YAML Error: Expected separator '---'
   Code: YAML_PARSE_ERR_NO_SEPARATOR
   Line: 5
   Document: 3
 at /perl5/lib/perl5/YAML/Loader.pm line 88.

c-libfyaml-json

 na
{
  "key": "value",
  "": "empty key"
}
{
  "key": "value",
  "": "empty key"
}
{
  "": null
}
{
  "": null
}

dotnet-yamldotnet-json

 na
Unhandled exception. YamlDotNet.Core.YamlException: (Line: 2, Col: 1, Idx: 4) - (Line: 2, Col: 1, Idx: 4): Exception during deserialization
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.set_Item(Object key, Object value)
   at YamlDotNet.Serialization.NodeDeserializers.DictionaryNodeDeserializer.DeserializeHelper(Type tKey, Type tValue, IParser parser, Func`3 nestedObjectDeserializer, IDictionary result)
   at YamlDotNet.Serialization.NodeDeserializers.DictionaryNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   --- End of inner exception stack trace ---
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.ValueDeserializers.AliasValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.Deserializer.Deserialize(IParser parser, Type type)
   at YamlDotNet.Serialization.Deserializer.Deserialize(TextReader input, Type type)
   at YamlDotNet.Serialization.Deserializer.Deserialize(TextReader input)
   at Program.Main(String[] commandLineArguments)
Aborted (core dumped)

hs-hsyaml-json

 na
{"":"empty key","key":"value"}
{"":"empty key","key":"value"}
{"":null}
{"":null}

java-snakeyaml-json

 na
Exception in thread "main" while parsing a block mapping
 in 'reader', line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
 in 'reader', line 3, column 1:
    : empty key
    ^

	at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:572)
	at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
	at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
	at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:235)
	at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:162)
	at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:95)
	at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:134)
	at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:494)
	at org.yaml.editor.Snake2Json.yamlToJson(Snake2Json.java:18)
	at org.yaml.editor.Snake2Json.main(Snake2Json.java:25)

js-jsyaml-json

 na
/node/node_modules/js-yaml/lib/js-yaml/loader.js:173
  throw generateError(state, message);
  ^
YAMLException: incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 3, column 1:
    : empty key
    ^
    at generateError (/node/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
    at throwError (/node/node_modules/js-yaml/lib/js-yaml/loader.js:173:9)
    at readBlockMapping (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1027:9)
    at composeNode (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1359:12)
    at readDocument (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1519:3)
    at loadDocuments (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1575:5)
    at Object.loadAll (/node/node_modules/js-yaml/lib/js-yaml/loader.js:1583:19)
    at Object.<anonymous> (/yaml/bin/js-jsyaml-json:7:13)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

js-yaml-json

 na
{
  "key": "value",
  "": "empty key"
}
{
  "key": "value",
  "": "empty key"
}
{
  "": null
}
{
  "": null
}

lua-lyaml-json

 na
luajit: 2:6: did not find expected key
stack traceback:
	[C]: in function 'error'
	/usr/local/share/lua/5.1/lyaml/init.lua:291: in function 'error'
	/usr/local/share/lua/5.1/lyaml/init.lua:310: in function 'parse'
	/usr/local/share/lua/5.1/lyaml/init.lua:428: in function 'load_node'
	/usr/local/share/lua/5.1/lyaml/init.lua:325: in function 'load_node'
	/usr/local/share/lua/5.1/lyaml/init.lua:482: in function 'load'
	/yaml/bin/lua-lyaml-json:6: in main chunk
	[C]: at 0x556048c10f97

perl-pp-json

 na
{
   "" : "empty key",
   "key" : "value"
}
{
   "" : "empty key",
   "key" : "value"
}
{
   "" : null
}
{
   "" : null
}

perl-pp-perl

 na
{
  '' => 'empty key',
  'key' => 'value'
}
{
  '' => 'empty key',
  'key' => 'value'
}
{
  '' => undef
}
{
  '' => undef
}

perl-pplibyaml-json

 na
YAML::PP::LibYAML Error: The problem:

    did not find expected key

was found at , line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

perl-syck-json

 na
Syck parser (line 3, column 1): syntax error at /perl5/lib/perl5/x86_64-linux-thread-multi/YAML/Syck.pm line 60, <> line 1.

perl-tiny-json

 na
YAML::Tiny failed to classify line ': empty key' at /yaml/bin/perl-tiny-json line 12.

perl-xs-json

 na
YAML::XS::Load Error: The problem:

    did not find expected key

was found at document: 1, line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

perl-yaml-json

 na
YAML Error: Expected separator '---'
   Code: YAML_PARSE_ERR_NO_SEPARATOR
   Line: 5
   Document: 3
 at /perl5/lib/perl5/YAML/Loader.pm line 88.

py-pyyaml-json

 na
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-json", line 19, in <module>
    for doc in yaml.load_all(sys.stdin.read(), Loader=yaml.FullLoader):
  File "/python/lib/python3.7/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
  File "/python/lib/python3.7/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
  in "<unicode string>", line 3, column 1:
    : empty key
    ^

py-ruamel-json

 na
Error json.dumps: <class 'TypeError'>
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-json", line 21, in <module>
    print(json.dumps(doc, sort_keys=True, skipkeys=True, indent=2))
  File "/usr/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.7/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.7/json/encoder.py", line 353, in _iterencode_dict
    items = sorted(dct.items(), key=lambda kv: kv[0])
TypeError: '<' not supported between instances of 'NoneType' and 'str'

py-ruamel-py

 na
{None: 'empty key', 'key': 'value'}
{None: 'empty key', 'key': 'value'}
{None: None}
{None: None}

ruby-psych-json

 na
/usr/lib/ruby/2.5.0/psych.rb:405:in `parse': (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1 (Psych::SyntaxError)
	from /usr/lib/ruby/2.5.0/psych.rb:405:in `parse_stream'
	from /usr/lib/ruby/2.5.0/psych.rb:488:in `load_stream'
	from /yaml/bin/ruby-psych-json:6:in `<main>'

c-libyaml-event

 ni
+STR
+DOC ---
+MAP
=VAL :key
=VAL :value
Parse error: did not find expected key

java-snakeyaml-event

 ni
Exception in thread "main" while parsing a block mapping
 in 'reader', line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
 in 'reader', line 3, column 1:
    : empty key
    ^

	at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:572)
	at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
	at org.yaml.snakeyaml.Yaml$3.hasNext(Yaml.java:654)
	at org.yaml.editor.Snake2Events.yamlToEvents(Snake2Events.java:111)
	at org.yaml.editor.Snake2Events.main(Snake2Events.java:119)

perl-pplibyaml-event

 ni
YAML::PP::LibYAML Error: The problem:

    did not find expected key

was found at , line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

perl-pplibyaml-perl

 ni
YAML::PP::LibYAML Error: The problem:

    did not find expected key

was found at , line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

perl-tiny-perl

 ni
YAML::Tiny failed to classify line ': empty key' at /yaml/bin/perl-tiny-perl line 15.

perl-xs-perl

 ni
YAML::XS::Load Error: The problem:

    did not find expected key

was found at document: 1, line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

py-pyyaml-event

 ni
+STR
+DOC ---
+MAP
=VAL :key
=VAL :value
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-event", line 7, in <module>
    for event in yaml.parse(sys.stdin.read()):
  File "/python/lib/python3.7/site-packages/yaml/__init__.py", line 75, in parse
    while loader.check_event():
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
  in "<unicode string>", line 3, column 1:
    : empty key
    ^

py-pyyaml-py

 ni
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-py", line 36, in <module>
    for doc in yaml.load_all(sys.stdin.read(), Loader=yaml.FullLoader):
  File "/python/lib/python3.7/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
  File "/python/lib/python3.7/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/python/lib/python3.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/python/lib/python3.7/site-packages/yaml/parser.py", line 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
  in "<unicode string>", line 3, column 1:
    : empty key
    ^