From 62848f94eef289d951370b8cd071821b588b21ea Mon Sep 17 00:00:00 2001 From: David Sichma Date: Fri, 19 Oct 2018 21:53:37 +0200 Subject: [PATCH] Fix: String::format Variant to String conversion Previosly String::format used variant.get_construct_string() to convert the passed Variants to Strings. This however did not match the expected printing behavior of some datatypes: Strings for example turned out escaped. This fix replaces the call to get_construct_string() with a simple conversion. This makes String::format consistent with "%s" % "sth" and formated Variants turn out like printed as expected. --- core/ustring.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index b55607946d9..16dd37d292a 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2774,16 +2774,13 @@ String String::format(const Variant &values, String placeholder) const { if (value_arr.size() == 2) { Variant v_key = value_arr[0]; - String key; - - key = v_key.get_construct_string(); + String key = v_key; if (key.left(1) == "\"" && key.right(key.length() - 1) == "\"") { key = key.substr(1, key.length() - 2); } Variant v_val = value_arr[1]; - String val; - val = v_val.get_construct_string(); + String val = v_val; if (val.left(1) == "\"" && val.right(val.length() - 1) == "\"") { val = val.substr(1, val.length() - 2); @@ -2795,8 +2792,7 @@ String String::format(const Variant &values, String placeholder) const { } } else { //Array structure ["RobotGuy","Logis","rookie"] Variant v_val = values_arr[i]; - String val; - val = v_val.get_construct_string(); + String val = v_val; if (val.left(1) == "\"" && val.right(val.length() - 1) == "\"") { val = val.substr(1, val.length() - 2); @@ -2815,8 +2811,8 @@ String String::format(const Variant &values, String placeholder) const { d.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - String key = E->get().get_construct_string(); - String val = d[E->get()].get_construct_string(); + String key = E->get(); + String val = d[E->get()]; if (key.left(1) == "\"" && key.right(key.length() - 1) == "\"") { key = key.substr(1, key.length() - 2);