From c08bd25dfa3b11772b437692444c59074f1aa4d9 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Wed, 12 Jul 2023 15:42:39 -0700 Subject: [PATCH 1/2] Quote values with an initial ":{" This combination is parsed as syntax by yamlerl and possibly other decoders, so we should quote when emitting for better compatibility. --- lib/ymlr/encode.ex | 1 + test/ymlr/encode_test.exs | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/ymlr/encode.ex b/lib/ymlr/encode.ex index 3e45c52..6f0a1b0 100644 --- a/lib/ymlr/encode.ex +++ b/lib/ymlr/encode.ex @@ -158,6 +158,7 @@ defmodule Ymlr.Encode do String.at(data, -1) in @quote_when_last -> with_quotes(data) String.starts_with?(data, "- ") -> with_quotes(data) String.starts_with?(data, ": ") -> with_quotes(data) + String.starts_with?(data, ":{") -> with_quotes(data) String.starts_with?(data, "? ") -> with_quotes(data) String.contains?(data, " #") -> with_quotes(data) String.contains?(data, ": ") -> with_quotes(data) diff --git a/test/ymlr/encode_test.exs b/test/ymlr/encode_test.exs index 13c16d1..7f094af 100644 --- a/test/ymlr/encode_test.exs +++ b/test/ymlr/encode_test.exs @@ -53,6 +53,7 @@ defmodule Ymlr.EncodeTest do assert MUT.to_s!("? explicit mapping key") == ~S('? explicit mapping key') assert MUT.to_s!("{flow_mapping") == ~S('{flow_mapping') assert MUT.to_s!("}flow_mapping") == ~S('}flow_mapping') + assert MUT.to_s!(":{ block flow") == ~S(':{ block flow') assert MUT.to_s!("[sequence_mapping") == ~S('[sequence_mapping') assert MUT.to_s!("]sequence_mapping") == ~S(']sequence_mapping') From 0884859361ba33597ad560a18b6c2a1e63521a05 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Wed, 12 Jul 2023 15:48:04 -0700 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc60de8..ec07234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +### Added + +- Quote values beginning with `:{` + ## [4.1.0] - 2023-04-23