From 67fc53664a4f74f7a1b0327628c9e4c103824dd8 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 4 Mar 2013 09:18:05 +0200 Subject: [PATCH] Quote empty strings #24 --- Data/Yaml.hs | 5 +++++ test/main.hs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/Data/Yaml.hs b/Data/Yaml.hs index b277294..6d69d48 100644 --- a/Data/Yaml.hs +++ b/Data/Yaml.hs @@ -114,6 +114,11 @@ objToEvents' (Array list) rest = objToEvents' (Object pairs) rest = EventMappingStart Nothing : foldr ($) (EventMappingEnd : rest) (map pairToEvents $ M.toList pairs) + +-- Empty strings need special handling to ensure they get quoted. This avoids: +-- https://github.com/snoyberg/yaml/issues/24 +objToEvents' (String "") rest = EventScalar "" StrTag SingleQuoted Nothing : rest + objToEvents' (String s) rest = EventScalar (encodeUtf8 s) StrTag PlainNoTag Nothing : rest objToEvents' Null rest = EventScalar "null" NullTag PlainNoTag Nothing : rest objToEvents' (Bool True) rest = EventScalar "true" BoolTag PlainNoTag Nothing : rest diff --git a/test/main.hs b/test/main.hs index 737bf53..c3b1391 100644 --- a/test/main.hs +++ b/test/main.hs @@ -241,7 +241,9 @@ sample = array [ D.String "foo" , object [ ("bar1", D.String "bar2") + , ("bar3", D.String "") ] + , D.String "" ] caseEncodeDecodeData :: Assertion