@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
21
21
#include " itemstackmetadata.h"
22
22
#include " util/serialize.h"
23
23
#include " util/strfnd.h"
24
+ #include < algorithm>
24
25
25
26
#define DESERIALIZE_START ' \x01 '
26
27
#define DESERIALIZE_KV_DELIM ' \x02 '
@@ -37,10 +38,22 @@ void ItemStackMetadata::clear()
37
38
updateToolCapabilities ();
38
39
}
39
40
41
+ static void sanitize_string (std::string &str)
42
+ {
43
+ str.erase (std::remove (str.begin (), str.end (), DESERIALIZE_START), str.end ());
44
+ str.erase (std::remove (str.begin (), str.end (), DESERIALIZE_KV_DELIM), str.end ());
45
+ str.erase (std::remove (str.begin (), str.end (), DESERIALIZE_PAIR_DELIM), str.end ());
46
+ }
47
+
40
48
bool ItemStackMetadata::setString (const std::string &name, const std::string &var)
41
49
{
42
- bool result = Metadata::setString (name, var);
43
- if (name == TOOLCAP_KEY)
50
+ std::string clean_name = name;
51
+ std::string clean_var = var;
52
+ sanitize_string (clean_name);
53
+ sanitize_string (clean_var);
54
+
55
+ bool result = Metadata::setString (clean_name, clean_var);
56
+ if (clean_name == TOOLCAP_KEY)
44
57
updateToolCapabilities ();
45
58
return result;
46
59
}
0 commit comments