Skip to content

Commit

Permalink
Ensure mapping values are quoted when they contain a : separtor
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
TristanCacqueray committed Mar 9, 2021
1 parent 4c89b1a commit efe02ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Data/Aeson/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions test/Test/Data/Aeson/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ tcHelloWorld =
{ tcName = "Hello World"
, tcInput =
[s|
{ "image": "node 10.15.3"
{ "image": "node: 10.15.3"
, "pipelines":
{ "default":
[ { "step":
Expand All @@ -230,7 +230,7 @@ tcHelloWorld =
}
|]
, tcOutput =
[s|image: node 10.15.3
[s|image: "node: 10.15.3"
pipelines:
default:
- step:
Expand Down

0 comments on commit efe02ec

Please sign in to comment.