mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Deprecate special handling of ${key}
syntax in metadata values (#12970)
This commit is contained in:
parent
3c7f26d937
commit
8817af07fb
@ -250,11 +250,12 @@ local formspec_escapes = {
|
||||
["["] = "\\[",
|
||||
["]"] = "\\]",
|
||||
[";"] = "\\;",
|
||||
[","] = "\\,"
|
||||
[","] = "\\,",
|
||||
["$"] = "\\$",
|
||||
}
|
||||
function core.formspec_escape(text)
|
||||
-- Use explicit character set instead of dot here because it doubles the performance
|
||||
return text and string.gsub(text, "[\\%[%];,]", formspec_escapes)
|
||||
return text and string.gsub(text, "[\\%[%];,$]", formspec_escapes)
|
||||
end
|
||||
|
||||
|
||||
|
@ -9,3 +9,4 @@ This document contains a list of breaking changes to be made in the next major v
|
||||
* remove `depends.txt` / `description.txt` (would simplify ContentDB and Minetest code a little)
|
||||
* rotate moon texture by 180°, making it coherent with the sun (see https://github.com/minetest/minetest/pull/11902)
|
||||
* remove undocumented `set_physics_override(num, num, num)`
|
||||
* remove special handling of `${key}` syntax in metadata values
|
||||
|
@ -6861,6 +6861,11 @@ Can be obtained via `item:get_meta()`.
|
||||
Base class used by [`StorageRef`], [`NodeMetaRef`], [`ItemStackMetaRef`],
|
||||
and [`PlayerMetaRef`].
|
||||
|
||||
Note: If a metadata value is in the format `${k}`, an attempt to get the value
|
||||
will return the value associated with key `k`. There is a low recursion limit.
|
||||
This behavior is **deprecated** and will be removed in a future version. Usage
|
||||
of the `${k}` syntax in formspecs is not deprecated.
|
||||
|
||||
### Methods
|
||||
|
||||
* `contains(key)`: Returns true if key present, otherwise false.
|
||||
|
@ -51,7 +51,7 @@ const std::string &IMetadata::getString(const std::string &name, std::string *pl
|
||||
return empty_string;
|
||||
}
|
||||
|
||||
return resolveString(*raw, place, recursion);
|
||||
return resolveString(*raw, place, recursion, true);
|
||||
}
|
||||
|
||||
bool IMetadata::getStringToRef(const std::string &name,
|
||||
@ -61,16 +61,21 @@ bool IMetadata::getStringToRef(const std::string &name,
|
||||
if (!raw)
|
||||
return false;
|
||||
|
||||
const std::string &resolved = resolveString(*raw, &str, recursion);
|
||||
const std::string &resolved = resolveString(*raw, &str, recursion, true);
|
||||
if (&resolved != &str)
|
||||
str = resolved;
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string &IMetadata::resolveString(const std::string &str, std::string *place,
|
||||
u16 recursion) const
|
||||
u16 recursion, bool deprecated) const
|
||||
{
|
||||
if (recursion <= 1 && str.substr(0, 2) == "${" && str[str.length() - 1] == '}') {
|
||||
if (deprecated) {
|
||||
warningstream << "Deprecated use of recursive resolution syntax in metadata: ";
|
||||
safe_print_string(warningstream, str);
|
||||
warningstream << std::endl;
|
||||
}
|
||||
// It may be the case that &str == place, but that's fine.
|
||||
return getString(str.substr(2, str.length() - 3), place, recursion + 1);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
|
||||
// Add support for variable names in values. Uses place like getString.
|
||||
const std::string &resolveString(const std::string &str, std::string *place,
|
||||
u16 recursion = 0) const;
|
||||
u16 recursion = 0, bool deprecated = false) const;
|
||||
|
||||
protected:
|
||||
// Returns nullptr to indicate absence of value. Uses place like getString.
|
||||
|
@ -459,6 +459,7 @@ inline void str_formspec_escape(std::string &str)
|
||||
str_replace(str, "[", "\\[");
|
||||
str_replace(str, ";", "\\;");
|
||||
str_replace(str, ",", "\\,");
|
||||
str_replace(str, "$", "\\$");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user