From a7c32b36d63d98df1123b96c497848c51d853b1b Mon Sep 17 00:00:00 2001 From: Cameron Ross Date: Thu, 5 Oct 2023 17:49:02 -0300 Subject: [PATCH] fix #325 - null simple keys not properly nullified --- source/dyaml/loader.d | 5 +++++ source/dyaml/scanner.d | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/dyaml/loader.d b/source/dyaml/loader.d index 2433a05..f0eda36 100644 --- a/source/dyaml/loader.d +++ b/source/dyaml/loader.d @@ -370,3 +370,8 @@ EOS"; auto e = loader.load().collectException!ScannerException(unused); assert(e.mark.name == filename); } +/// https://github.com/dlang-community/D-YAML/issues/325 +@safe unittest +{ + assert(Loader.fromString("--- {x: a}").load()["x"] == "a"); +} diff --git a/source/dyaml/scanner.d b/source/dyaml/scanner.d index e0ff74d..0a28523 100644 --- a/source/dyaml/scanner.d +++ b/source/dyaml/scanner.d @@ -313,8 +313,11 @@ struct Scanner { const oldLength = possibleSimpleKeys_.length; possibleSimpleKeys_.length = flowLevel_ + 1; - //No need to initialize the last element, it's already done in the next line. - possibleSimpleKeys_[oldLength .. flowLevel_] = SimpleKey.init; + // Make sure all the empty keys are null + foreach (ref emptyKey; possibleSimpleKeys_[oldLength .. flowLevel_]) + { + emptyKey.isNull = true; + } } possibleSimpleKeys_[flowLevel_] = key; }