From 31e159167e8dd6ccddc616b4595286673e7a1154 Mon Sep 17 00:00:00 2001 From: Andre Vehreschild Date: Thu, 21 Apr 2022 12:13:32 +0200 Subject: [PATCH] Special char & not treated ok when auto-quoting emit. A key having an ampersand in it does not trigger quoting in the emit, when auto-quoting is enabled. --- src/emitterutils.cpp | 4 ++-- src/exp.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp index c6ad5e5..6cdf6de 100644 --- a/src/emitterutils.cpp +++ b/src/emitterutils.cpp @@ -176,11 +176,11 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType, static const RegEx& disallowed_flow = Exp::EndScalarInFlow() | (Exp::BlankOrBreak() + Exp::Comment()) | Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() | - Exp::Tab(); + Exp::Tab() | Exp::Ampersand(); static const RegEx& disallowed_block = Exp::EndScalar() | (Exp::BlankOrBreak() + Exp::Comment()) | Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() | - Exp::Tab(); + Exp::Tab() | Exp::Ampersand(); const RegEx& disallowed = flowType == FlowType::Flow ? disallowed_flow : disallowed_block; diff --git a/src/exp.h b/src/exp.h index a0d6d76..c8837f0 100644 --- a/src/exp.h +++ b/src/exp.h @@ -117,6 +117,10 @@ inline const RegEx& ValueInJSONFlow() { static const RegEx e = RegEx(':'); return e; } +inline const RegEx& Ampersand() { + static const RegEx e = RegEx('&'); + return e; +} inline const RegEx Comment() { static const RegEx e = RegEx('#'); return e;