diff options
author | kobewi <kobewi4e@gmail.com> | 2022-11-09 14:00:51 +0100 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-11-09 14:00:51 +0100 |
commit | 0d122ce45998b33e923ac406129f64b5e9f3affb (patch) | |
tree | 160a4a71354f8fc20194338dc06b45ff60bad8a3 /core | |
parent | 29de658c2908b6b50b218225539f9779292eb870 (diff) |
Allow to escape closing brackets in CFG tags
Diffstat (limited to 'core')
-rw-r--r-- | core/io/config_file.cpp | 4 | ||||
-rw-r--r-- | core/variant/variant_parser.cpp | 21 |
2 files changed, 21 insertions, 4 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index f84a95347a..604cf67c1d 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -208,7 +208,7 @@ Error ConfigFile::_internal_save(Ref<FileAccess> file) { file->store_string("\n"); } if (!E.key.is_empty()) { - file->store_string("[" + E.key + "]\n\n"); + file->store_string("[" + E.key.replace("]", "\\]") + "]\n\n"); } for (const KeyValue<String, Variant> &F : E.value) { @@ -308,7 +308,7 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) if (!assign.is_empty()) { set_value(section, assign, value); } else if (!next_tag.name.is_empty()) { - section = next_tag.name; + section = next_tag.name.replace("\\]", "]"); } } diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index d2e4d752a4..593036519e 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1304,6 +1304,7 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin if (p_simple_tag) { r_tag.name = ""; r_tag.fields.clear(); + bool escaping = false; if (p_stream->is_utf8()) { CharString cs; @@ -1314,7 +1315,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin return ERR_PARSE_ERROR; } if (c == ']') { - break; + if (escaping) { + escaping = false; + } else { + break; + } + } else if (c == '\\') { + escaping = true; + } else { + escaping = false; } cs += c; } @@ -1327,7 +1336,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin return ERR_PARSE_ERROR; } if (c == ']') { - break; + if (escaping) { + escaping = false; + } else { + break; + } + } else if (c == '\\') { + escaping = true; + } else { + escaping = false; } r_tag.name += String::chr(c); } |