From e7e095da3fd9140cfbbe11dd178981633819d642 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 20 Dec 2019 10:03:15 +0800 Subject: Encodes property names properly in project.godot --- core/project_settings.cpp | 5 +---- core/ustring.cpp | 13 +++++++++++++ core/ustring.h | 2 ++ core/variant_parser.cpp | 3 --- 4 files changed, 16 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/project_settings.cpp b/core/project_settings.cpp index 067578e354..52087df548 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -769,10 +769,7 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Mapget().find(" ") != -1) - file->store_string(F->get().quote() + "=" + vstr + "\n"); - else - file->store_string(F->get() + "=" + vstr + "\n"); + file->store_string(F->get().property_name_encode() + "=" + vstr + "\n"); } } diff --git a/core/ustring.cpp b/core/ustring.cpp index 502e6a5a88..09a02a09be 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -4059,6 +4059,19 @@ String String::percent_decode() const { return String::utf8(pe.ptr()); } +String String::property_name_encode() const { + // Escape and quote strings with extended ASCII or further Unicode characters + // as well as '"', '=' or ' ' (32) + const CharType *cstr = c_str(); + for (int i = 0; cstr[i]; i++) { + if (cstr[i] == '=' || cstr[i] == '"' || cstr[i] < 33 || cstr[i] > 126) { + return "\"" + c_escape_multiline() + "\""; + } + } + // Keep as is + return *this; +} + String String::get_basename() const { int pos = find_last("."); diff --git a/core/ustring.h b/core/ustring.h index dfc5044942..c20f659c59 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -338,6 +338,8 @@ public: String percent_encode() const; String percent_decode() const; + String property_name_encode() const; + bool is_valid_identifier() const; bool is_valid_integer() const; bool is_valid_float() const; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index fe2c981c3c..9a5f9c9ede 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1530,9 +1530,6 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r } else if (c != '=') { what += String::chr(c); } else { - if (p_stream->is_utf8()) { - what.parse_utf8(what.ascii(true).get_data()); - } r_assign = what; Token token; get_token(p_stream, token, line, r_err_str); -- cgit v1.2.3