From ff898da5767f8efc5b19bcbb440e8b5d1266a968 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Tue, 9 Mar 2021 19:10:11 +0000 Subject: [PATCH] Ensure mapping values are quoted when they contain a `: ` separtor This change prevents issue when the encoded yaml is invalid: This object: { key = "value: value" } Is encoded as: key: value: value Instead of: key: "value: value" Signed-off-by: Tristan Cacqueray --- src/Data/Aeson/Yaml.hs | 3 ++- test/Test/Data/Aeson/Yaml.hs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Data/Aeson/Yaml.hs b/src/Data/Aeson/Yaml.hs index c9070c3..0cf2f6e 100644 --- a/src/Data/Aeson/Yaml.hs +++ b/src/Data/Aeson/Yaml.hs @@ -139,7 +139,8 @@ encodeText canMultiline alwaysQuote level s s /= "" && -- s is not empty Text.all isAllowed s && -- s consists of acceptable chars (Data.Char.isAlpha headS || -- head of s is a char in A-Z or a-z or indicates a filepath - headS == '/') + headS == '/') && + not (Text.isInfixOf ": " s) -- s contains a mapping separator isBoolString | Text.length s > 5 = False | otherwise = diff --git a/test/Test/Data/Aeson/Yaml.hs b/test/Test/Data/Aeson/Yaml.hs index 55c5fc4..a214dea 100644 --- a/test/Test/Data/Aeson/Yaml.hs +++ b/test/Test/Data/Aeson/Yaml.hs @@ -215,7 +215,7 @@ tcHelloWorld = { tcName = "Hello World" , tcInput = [s| -{ "image": "node 10.15.3" +{ "image": "node: 10.15.3" , "pipelines": { "default": [ { "step": @@ -230,7 +230,7 @@ tcHelloWorld = } |] , tcOutput = - [s|image: node 10.15.3 + [s|image: "node: 10.15.3" pipelines: default: - step: