Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote and escape ConfigFile keys when necessary #52180

Merged
merged 1 commit into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/io/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Error ConfigFile::_internal_save(FileAccess *file) {
for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) {
String vstr;
VariantWriter::write_to_string(F.get(), vstr);
file->store_string(F.key() + "=" + vstr + "\n");
file->store_string(F.key().property_name_encode() + "=" + vstr + "\n");
}
}

Expand Down
11 changes: 9 additions & 2 deletions tests/test_config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ TEST_CASE("[ConfigFile] Saving file") {
config_file.set_value("player", "position", Vector2(3, 4));
config_file.set_value("graphics", "antialiasing", true);
config_file.set_value("graphics", "antiAliasing", false);
config_file.set_value("quoted", String::utf8("静音"), 42);
config_file.set_value("quoted", "a=b", 7);

#ifdef WINDOWS_ENABLED
const String config_path = OS::get_singleton()->get_environment("TEMP").plus_file("config.ini");
Expand All @@ -132,7 +134,7 @@ TEST_CASE("[ConfigFile] Saving file") {
config_file.save(config_path);

// Expected contents of the saved ConfigFile.
const String contents = R"([player]
const String contents = String::utf8(R"([player]

name="Unnamed Player"
tagline="Waiting
Expand All @@ -145,7 +147,12 @@ position=Vector2(3, 4)

antialiasing=true
antiAliasing=false
)";

[quoted]

"静音"=42
"a=b"=7
)");

FileAccessRef file = FileAccess::open(config_path, FileAccess::READ);
CHECK_MESSAGE(file->get_as_utf8_string() == contents,
Expand Down