-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathyaml-cpp.patch
More file actions
180 lines (165 loc) · 6.41 KB
/
yaml-cpp.patch
File metadata and controls
180 lines (165 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 46dc180..b746ac1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
# 3.5 is actually available almost everywhere, but this a good minimum
-cmake_minimum_required(VERSION 3.4)
+cmake_minimum_required(VERSION 3.10)
# enable MSVC_RUNTIME_LIBRARY target property
# see https://cmake.org/cmake/help/latest/policy/CMP0091.html
diff --git a/include/yaml-cpp/emittermanip.h b/include/yaml-cpp/emittermanip.h
index 976d149..ba73a48 100644
--- a/include/yaml-cpp/emittermanip.h
+++ b/include/yaml-cpp/emittermanip.h
@@ -32,6 +32,7 @@ enum EMITTER_MANIP {
UpperNull,
CamelNull,
TildeNull,
+ EmptyNull,
// bool manipulators
YesNoBool, // yes, no
diff --git a/include/yaml-cpp/exceptions.h b/include/yaml-cpp/exceptions.h
index f6b2602..a4c5537 100644
--- a/include/yaml-cpp/exceptions.h
+++ b/include/yaml-cpp/exceptions.h
@@ -87,6 +87,7 @@ const char* const INVALID_ANCHOR = "invalid anchor";
const char* const INVALID_ALIAS = "invalid alias";
const char* const INVALID_TAG = "invalid tag";
const char* const BAD_FILE = "bad file";
+const char* const NON_UNIQUE_MAP_KEY = "map keys must be unique";
template <typename T>
inline const std::string KEY_NOT_FOUND_WITH_KEY(
@@ -298,6 +299,16 @@ class YAML_CPP_API BadFile : public Exception {
BadFile(const BadFile&) = default;
~BadFile() YAML_CPP_NOEXCEPT override;
};
+
+class YAML_CPP_API NonUniqueMapKey : public RepresentationException {
+ public:
+ template <typename Key>
+ NonUniqueMapKey(const Mark& mark_, const Key& key)
+ : RepresentationException(mark_, ErrorMsg::NON_UNIQUE_MAP_KEY) {}
+ NonUniqueMapKey(const NonUniqueMapKey&) = default;
+ ~NonUniqueMapKey() YAML_CPP_NOEXCEPT override;
+};
+
} // namespace YAML
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h
index b38038d..9138fe6 100644
--- a/include/yaml-cpp/node/detail/impl.h
+++ b/include/yaml-cpp/node/detail/impl.h
@@ -218,7 +218,7 @@ inline void node_data::force_insert(const Key& key, const Value& value,
node& k = convert_to_node(key, pMemory);
node& v = convert_to_node(value, pMemory);
- insert_map_pair(k, v);
+ insert_map_pair(k, v, true);
}
template <typename T>
diff --git a/include/yaml-cpp/node/detail/node_data.h b/include/yaml-cpp/node/detail/node_data.h
index 07cf81a..ed7d9cd 100644
--- a/include/yaml-cpp/node/detail/node_data.h
+++ b/include/yaml-cpp/node/detail/node_data.h
@@ -90,7 +90,7 @@ class YAML_CPP_API node_data {
void reset_sequence();
void reset_map();
- void insert_map_pair(node& key, node& value);
+ void insert_map_pair(node& key, node& value, bool force = false);
void convert_to_map(const shared_memory_holder& pMemory);
void convert_sequence_to_map(const shared_memory_holder& pMemory);
diff --git a/src/emitter.cpp b/src/emitter.cpp
index 4d48307..a188cca 100644
--- a/src/emitter.cpp
+++ b/src/emitter.cpp
@@ -721,7 +721,7 @@ Emitter& Emitter::Write(const std::string& str) {
StringEscaping::value stringEscaping = GetStringEscapingStyle(m_pState->GetOutputCharset());
- const StringFormat::value strFormat =
+ const StringFormat::value strFormat = str.compare(0, 2, "|\n") == 0 ? StringFormat::Literal :
Utils::ComputeStringFormat(str, m_pState->GetStringFormat(),
m_pState->CurGroupFlowType(), stringEscaping == StringEscaping::NonAscii);
@@ -816,6 +816,8 @@ const char* Emitter::ComputeNullName() const {
return "NULL";
case CamelNull:
return "Null";
+ case EmptyNull:
+ return "";
case TildeNull:
// fallthrough
default:
diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp
index 3dbe401..0dd0b17 100644
--- a/src/emitterstate.cpp
+++ b/src/emitterstate.cpp
@@ -305,6 +305,7 @@ bool EmitterState::SetNullFormat(EMITTER_MANIP value, FmtScope::value scope) {
case LowerNull:
case UpperNull:
case CamelNull:
+ case EmptyNull:
case TildeNull:
_Set(m_nullFmt, value, scope);
return true;
diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp
index 6cdf6de..b48b7c0 100644
--- a/src/emitterutils.cpp
+++ b/src/emitterutils.cpp
@@ -365,7 +365,7 @@ bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
std::size_t indent) {
- out << "|\n";
+ out << (str.compare(0, 2, "|\n") == 0 ? "" : "|\n");
int codePoint;
for (std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
diff --git a/src/exceptions.cpp b/src/exceptions.cpp
index 43a7976..af99fd6 100644
--- a/src/exceptions.cpp
+++ b/src/exceptions.cpp
@@ -17,4 +17,5 @@ BadPushback::~BadPushback() YAML_CPP_NOEXCEPT = default;
BadInsert::~BadInsert() YAML_CPP_NOEXCEPT = default;
EmitterException::~EmitterException() YAML_CPP_NOEXCEPT = default;
BadFile::~BadFile() YAML_CPP_NOEXCEPT = default;
+NonUniqueMapKey::~NonUniqueMapKey() YAML_CPP_NOEXCEPT = default;
} // namespace YAML
diff --git a/src/exp.h b/src/exp.h
index c8837f0..5db3ee4 100644
--- a/src/exp.h
+++ b/src/exp.h
@@ -118,7 +118,7 @@ inline const RegEx& ValueInJSONFlow() {
return e;
}
inline const RegEx& Ampersand() {
- static const RegEx e = RegEx('&');
+ static const RegEx e = RegEx("^&| &");
return e;
}
inline const RegEx Comment() {
diff --git a/src/node_data.cpp b/src/node_data.cpp
index 8f5422a..23ad892 100644
--- a/src/node_data.cpp
+++ b/src/node_data.cpp
@@ -279,7 +279,12 @@ void node_data::reset_map() {
m_undefinedPairs.clear();
}
-void node_data::insert_map_pair(node& key, node& value) {
+void node_data::insert_map_pair(node& key, node& value, bool force) {
+ if (!force && !key.scalar().empty())
+ for (const auto& mapEntry : m_map)
+ if (mapEntry.first->scalar() == key.scalar())
+ throw NonUniqueMapKey(m_mark, key);
+
m_map.emplace_back(&key, &value);
if (!key.is_defined() || !value.is_defined())
diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp
index 9d0c790..37355aa 100644
--- a/test/integration/load_node_test.cpp
+++ b/test/integration/load_node_test.cpp
@@ -360,5 +360,9 @@ TEST(LoadNodeTest, BlockCRNLEncoded) {
EXPECT_EQ(1, node["followup"].as<int>());
}
+TEST(LoadNodeTest, NonUniqueMapKey) {
+ EXPECT_THROW(Load("{a: A, b: B, a: A}"), NonUniqueMapKey);
+}
+
} // namespace
} // namespace YAML