diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-08-28 23:49:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-28 23:49:00 +0200 |
commit | 4d08a737fb868b4c2f47946aea7c9ec4ee97894d (patch) | |
tree | 7952648e7e0a6e8759958299921b4de146d7cf6a | |
parent | 921bc712934a721095061c3acf422c29737b336f (diff) | |
parent | 597d489a20d3755dae4b92ac7667e058d68b3d83 (diff) |
Merge pull request #52180 from timothyqiu/config-file-prop
Quote and escape ConfigFile keys when necessary
-rw-r--r-- | core/io/config_file.cpp | 2 | ||||
-rw-r--r-- | tests/test_config_file.h | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 55793aa5a4..49fa73dab2 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -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"); } } diff --git a/tests/test_config_file.h b/tests/test_config_file.h index 33fd30ffa1..e3f40e16fd 100644 --- a/tests/test_config_file.h +++ b/tests/test_config_file.h @@ -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"); @@ -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 @@ -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, |