diff options
author | rubenwardy <rw@rubenwardy.com> | 2021-01-28 16:32:37 +0000 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2021-01-28 21:33:10 +0000 |
commit | b5956bde259faa240a81060ff4e598e25ad52dae (patch) | |
tree | 9cf8171f648ad112a4570f208dc71406950562df | |
parent | ed0882fd58fb0f663cc115d23a11643874facc06 (diff) | |
download | minetest-b5956bde259faa240a81060ff4e598e25ad52dae.tar.gz minetest-b5956bde259faa240a81060ff4e598e25ad52dae.tar.bz2 minetest-b5956bde259faa240a81060ff4e598e25ad52dae.zip |
Sanitize ItemStack meta text
-rw-r--r-- | src/itemstackmetadata.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/itemstackmetadata.cpp b/src/itemstackmetadata.cpp index 4aa1a0903..7a26fbb0e 100644 --- a/src/itemstackmetadata.cpp +++ b/src/itemstackmetadata.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemstackmetadata.h" #include "util/serialize.h" #include "util/strfnd.h" +#include <algorithm> #define DESERIALIZE_START '\x01' #define DESERIALIZE_KV_DELIM '\x02' @@ -37,10 +38,22 @@ void ItemStackMetadata::clear() updateToolCapabilities(); } +static void sanitize_string(std::string &str) +{ + str.erase(std::remove(str.begin(), str.end(), DESERIALIZE_START), str.end()); + str.erase(std::remove(str.begin(), str.end(), DESERIALIZE_KV_DELIM), str.end()); + str.erase(std::remove(str.begin(), str.end(), DESERIALIZE_PAIR_DELIM), str.end()); +} + bool ItemStackMetadata::setString(const std::string &name, const std::string &var) { - bool result = Metadata::setString(name, var); - if (name == TOOLCAP_KEY) + std::string clean_name = name; + std::string clean_var = var; + sanitize_string(clean_name); + sanitize_string(clean_var); + + bool result = Metadata::setString(clean_name, clean_var); + if (clean_name == TOOLCAP_KEY) updateToolCapabilities(); return result; } |