Skip to content

Commit 2eb4538

Browse files
authored
[yaml] Use DoubleQuoted for octals instead of LocalTag (#4419)
This pull request updates the YAML emission logic to use double quotes for strings that look like octal numbers, rather than attempting to them explicitly as strings. Corresponding unit tests have also been updated to reflect this new behavior. YAML::DoubleQuoted was originally avoided in favor of explicit tags due to perceived issues with timeouts using DoubleQuoted, but it appears that this is not a result of the use of DoubleQuoted (loading some cloud-init YAMLs simply takes a long time!) fixes #4418
2 parents a819c6e + 6c4d2ae commit 2eb4538

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/utils/yaml_node_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ std::string mp::utils::emit_yaml(const YAML::Node& node)
131131
if (value.length() >= 2 && value[0] == '0' &&
132132
std::all_of(value.begin() + 1, value.end(), ::isdigit))
133133
{
134-
emitter << YAML::LocalTag("str") << value;
134+
emitter << YAML::DoubleQuoted << value;
135135
break;
136136
}
137137
}

tests/test_yaml_node_utils.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,10 @@ TEST(UtilsTests, emitYamlWithOctalString)
178178

179179
const std::string result = mpu::emit_yaml(node);
180180

181-
// The octal strings should be tagged as strings to preserve their format
182-
EXPECT_TRUE(result.find("permissions: !str \"0755\"") != std::string::npos ||
183-
result.find("permissions: !str 0755") != std::string::npos);
184-
EXPECT_TRUE(result.find("another_permission: !str \"0644\"") != std::string::npos ||
185-
result.find("another_permission: !str 0644") != std::string::npos);
186-
// Non-octal strings should not be tagged
181+
// The octal strings should be double-quoted to preserve their format as strings
182+
EXPECT_TRUE(result.find("permissions: \"0755\"") != std::string::npos);
183+
EXPECT_TRUE(result.find("another_permission: \"0644\"") != std::string::npos);
184+
// Non-octal strings should not be quoted (or may be quoted, both are acceptable)
187185
EXPECT_TRUE(result.find("not_octal: 0abc") != std::string::npos ||
188186
result.find("not_octal: \"0abc\"") != std::string::npos);
189187
EXPECT_TRUE(result.find("regular_string: hello") != std::string::npos ||

0 commit comments

Comments
 (0)