!8 Add the support to parsing a null value.
From: @cherry530 Reviewed-by: @lyn1001 Signed-off-by: @lyn1001
This commit is contained in:
commit
f5d0759b3d
38
Add-the-support-to-parsing-a-null-value.patch
Normal file
38
Add-the-support-to-parsing-a-null-value.patch
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h
|
||||||
|
index 7a3deac..58ae529 100644
|
||||||
|
--- a/include/yaml-cpp/node/impl.h
|
||||||
|
+++ b/include/yaml-cpp/node/impl.h
|
||||||
|
@@ -112,8 +112,10 @@ template <typename S>
|
||||||
|
struct as_if<std::string, S> {
|
||||||
|
explicit as_if(const Node& node_) : node(node_) {}
|
||||||
|
const Node& node;
|
||||||
|
-
|
||||||
|
+
|
||||||
|
std::string operator()(const S& fallback) const {
|
||||||
|
+ if (node.Type() == NodeType::Null)
|
||||||
|
+ return "null";
|
||||||
|
if (node.Type() != NodeType::Scalar)
|
||||||
|
return fallback;
|
||||||
|
return node.Scalar();
|
||||||
|
@@ -142,6 +144,8 @@ struct as_if<std::string, void> {
|
||||||
|
const Node& node;
|
||||||
|
|
||||||
|
std::string operator()() const {
|
||||||
|
+ if (node.Type() == NodeType::Null)
|
||||||
|
+ return "null";
|
||||||
|
if (node.Type() != NodeType::Scalar)
|
||||||
|
throw TypedBadConversion<std::string>(node.Mark());
|
||||||
|
return node.Scalar();
|
||||||
|
diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp
|
||||||
|
index 4f4f28e..1fb8415 100644
|
||||||
|
--- a/test/integration/load_node_test.cpp
|
||||||
|
+++ b/test/integration/load_node_test.cpp
|
||||||
|
@@ -249,6 +249,8 @@ TEST(NodeTest, IncompleteJson) {
|
||||||
|
TEST(NodeTest, LoadTildeAsNull) {
|
||||||
|
Node node = Load("~");
|
||||||
|
ASSERT_TRUE(node.IsNull());
|
||||||
|
+ EXPECT_EQ(node.as<std::string>(), "null");
|
||||||
|
+ EXPECT_EQ(node.as<std::string>("~"), "null");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(NodeTest, LoadTagWithParenthesis) {
|
||||||
@ -1,11 +1,12 @@
|
|||||||
Name: yaml-cpp
|
Name: yaml-cpp
|
||||||
Version: 0.6.3
|
Version: 0.6.3
|
||||||
Release: 1
|
Release: 2
|
||||||
Summary: A YAML parser and emitter in C++.
|
Summary: A YAML parser and emitter in C++.
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: https://github.com/jbeder/yaml-cpp
|
URL: https://github.com/jbeder/yaml-cpp
|
||||||
Source0: https://github.com/jbeder/yaml-cpp/archive/%{name}-%{version}.tar.gz
|
Source0: https://github.com/jbeder/yaml-cpp/archive/%{name}-%{version}.tar.gz
|
||||||
Patch0001: CVE-2017-5950.patch
|
Patch0001: CVE-2017-5950.patch
|
||||||
|
Patch0002: Add-the-support-to-parsing-a-null-value.patch
|
||||||
BuildRequires: cmake gcc gcc-c++
|
BuildRequires: cmake gcc gcc-c++
|
||||||
|
|
||||||
%description
|
%description
|
||||||
@ -68,5 +69,8 @@ cd -
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Jun 14 2024 xu_ping <707078654@qq.com> - 0.6.3-2
|
||||||
|
- Add the support to parsing a null value.
|
||||||
|
|
||||||
* Mon Jan 6 2020 Senlin Xia <xiasenlin1@huawei.com> - 0.6.3-1
|
* Mon Jan 6 2020 Senlin Xia <xiasenlin1@huawei.com> - 0.6.3-1
|
||||||
- Package init
|
- Package init
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user