From bd549ca017c226071194630edf4328a754d6d856 Mon Sep 17 00:00:00 2001 From: Cameron Ross Date: Sat, 19 Sep 2020 18:27:24 -0300 Subject: [PATCH] fix issue #258 --- source/dyaml/loader.d | 8 ++++++++ source/dyaml/scanner.d | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/dyaml/loader.d b/source/dyaml/loader.d index c7703e6..780862e 100644 --- a/source/dyaml/loader.d +++ b/source/dyaml/loader.d @@ -385,3 +385,11 @@ struct Loader auto rootNode = loader.load(); } + +//Issue #258 - https://github.com/dlang-community/D-YAML/issues/258 +@safe unittest +{ + auto yaml = "{\n\"root\": {\n\t\"key\": \"value\"\n }\n}"; + auto doc = Loader.fromString(yaml).load(); + assert(doc.isValid); +} diff --git a/source/dyaml/scanner.d b/source/dyaml/scanner.d index 8bb9af0..d4f8253 100644 --- a/source/dyaml/scanner.d +++ b/source/dyaml/scanner.d @@ -57,6 +57,8 @@ alias isBreakOrSpace = among!(' ', '\0', '\n', '\r', '\u0085', '\u2028', '\u2029 alias isWhiteSpace = among!(' ', '\t', '\0', '\n', '\r', '\u0085', '\u2028', '\u2029'); +alias isNonLinebreakWhitespace = among!(' ', '\t'); + alias isNonScalarStartCharacter = among!('-', '?', ':', ',', '[', ']', '{', '}', '#', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`', ' ', '\t', '\0', '\n', '\r', '\u0085', '\u2028', '\u2029'); @@ -800,8 +802,16 @@ struct Scanner for(;;) { - findNextNonSpace(); - + //All whitespace in flow context is ignored, even whitespace + // not allowed in other contexts + if (flowLevel_ > 0) + { + while(reader_.peekByte().isNonLinebreakWhitespace) { reader_.forward(); } + } + else + { + findNextNonSpace(); + } if(reader_.peekByte() == '#') { scanToNextBreak(); } if(scanLineBreak() != '\0') {