Run unescape_enriched *after* unescape_string.

Doing it the other way round was a mistake, since it breaks
minetest.formspec_escape with escape sequences that contain
special characters.
master
Ekdohibs 2016-05-05 19:08:45 +02:00
parent d5c3db9c41
commit 4d9dbceb39
2 changed files with 25 additions and 30 deletions

View File

@ -422,7 +422,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
if (selected == "true")
fselected = true;
std::wstring wlabel = utf8_to_wide(label);
std::wstring wlabel = utf8_to_wide(unescape_string(label));
core::rect<s32> rect = core::rect<s32>(
pos.X, pos.Y + ((imgsize.Y/2) - m_btn_height),
@ -618,7 +618,7 @@ void GUIFormSpecMenu::parseButton(parserData* data,std::string element,
if(!data->explicit_size)
warningstream<<"invalid use of button without a size[] element"<<std::endl;
std::wstring wlabel = utf8_to_wide(label);
std::wstring wlabel = utf8_to_wide(unescape_string(label));
FieldSpec spec(
name,
@ -752,7 +752,7 @@ void GUIFormSpecMenu::parseTable(parserData* data,std::string element)
spec.ftype = f_Table;
for (unsigned int i = 0; i < items.size(); ++i) {
items[i] = unescape_string(unescape_enriched(items[i]));
items[i] = unescape_enriched(unescape_string(items[i]));
}
//now really show table
@ -824,7 +824,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element)
spec.ftype = f_Table;
for (unsigned int i = 0; i < items.size(); ++i) {
items[i] = unescape_string(unescape_enriched(items[i]));
items[i] = unescape_enriched(unescape_string(items[i]));
}
//now really show list
@ -895,7 +895,7 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
}
for (unsigned int i=0; i < items.size(); i++) {
e->addItem(unescape_string(unescape_enriched(
e->addItem(unescape_enriched(unescape_string(
utf8_to_wide(items[i]))).c_str());
}
@ -945,7 +945,7 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
std::wstring wlabel = utf8_to_wide(label);
std::wstring wlabel = utf8_to_wide(unescape_string(label));
FieldSpec spec(
name,
@ -1009,12 +1009,12 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
default_val = m_form_src->resolveText(default_val);
std::wstring wlabel = utf8_to_wide(label);
std::wstring wlabel = utf8_to_wide(unescape_string(label));
FieldSpec spec(
name,
wlabel,
utf8_to_wide(default_val),
utf8_to_wide(unescape_string(default_val)),
258+m_fields.size()
);
@ -1105,12 +1105,12 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,
default_val = m_form_src->resolveText(default_val);
std::wstring wlabel = utf8_to_wide(label);
std::wstring wlabel = utf8_to_wide(unescape_string(label));
FieldSpec spec(
name,
wlabel,
utf8_to_wide(default_val),
utf8_to_wide(unescape_string(default_val)),
258+m_fields.size()
);
@ -1218,7 +1218,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
// in the integer cases: 0.4 is not exactly
// representable in binary floating point.
s32 posy = pos.Y + ((float)i) * spacing.Y * 2.0 / 5.0;
std::wstring wlabel = utf8_to_wide(lines[i]);
std::wstring wlabel = utf8_to_wide(unescape_string(lines[i]));
core::rect<s32> rect = core::rect<s32>(
pos.X, posy - m_btn_height,
pos.X + m_font->getDimension(wlabel.c_str()).Width,
@ -1250,8 +1250,8 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element)
((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
{
std::vector<std::string> v_pos = split(parts[0],',');
std::wstring text = unescape_string(
unescape_enriched(utf8_to_wide(parts[1])));
std::wstring text = unescape_enriched(
unescape_string(utf8_to_wide(parts[1])));
MY_CHECKPOS("vertlabel",1);
@ -1339,7 +1339,7 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
image_name = unescape_string(image_name);
pressed_image_name = unescape_string(pressed_image_name);
std::wstring wlabel = utf8_to_wide(label);
std::wstring wlabel = utf8_to_wide(unescape_string(label));
FieldSpec spec(
name,
@ -1437,7 +1437,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element)
e->setNotClipped(true);
for (unsigned int i = 0; i < buttons.size(); i++) {
e->addTab(unescape_string(unescape_enriched(
e->addTab(unescape_enriched(unescape_string(
utf8_to_wide(buttons[i]))).c_str(), -1);
}
@ -1473,6 +1473,9 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
std::string name = parts[3];
std::string label = parts[4];
label = unescape_string(label);
item_name = unescape_string(item_name);
MY_CHECKPOS("itemimagebutton",0);
MY_CHECKGEOM("itemimagebutton",1);
@ -1611,14 +1614,14 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, std::string element)
std::vector<std::string> parts = split(element,';');
if (parts.size() == 2) {
std::string name = parts[0];
m_tooltips[name] = TooltipSpec(parts[1],
m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
m_default_tooltip_bgcolor, m_default_tooltip_color);
return;
} else if (parts.size() == 4) {
std::string name = parts[0];
video::SColor tmp_color1, tmp_color2;
if ( parseColorString(parts[2], tmp_color1, false) && parseColorString(parts[3], tmp_color2, false) ) {
m_tooltips[name] = TooltipSpec(parts[1],
m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
tmp_color1, tmp_color2);
return;
}

View File

@ -192,14 +192,6 @@ class GUIFormSpecMenu : public GUIModalMenu
bool scale;
};
/* The responsibility of unescaping the strings has been shifted
* from the formspec parsing methods to the draw methods.
* There still are a few exceptions:
* - Vertical label, because it modifies the string by inserting
* '\n' between each character,
* - Tab header, because it gives the string immediately to
* Irrlicht and we can't unescape it later.
*/
struct FieldSpec
{
FieldSpec()
@ -210,8 +202,8 @@ class GUIFormSpecMenu : public GUIModalMenu
fname(name),
fid(id)
{
flabel = unescape_string(unescape_enriched(label));
fdefault = unescape_string(unescape_enriched(default_text));
flabel = unescape_enriched(label);
fdefault = unescape_enriched(default_text);
send = false;
ftype = f_Unknown;
is_exit = false;
@ -247,7 +239,7 @@ class GUIFormSpecMenu : public GUIModalMenu
bgcolor(a_bgcolor),
color(a_color)
{
tooltip = unescape_string(unescape_enriched(utf8_to_wide(a_tooltip)));
tooltip = unescape_enriched(utf8_to_wide(a_tooltip));
}
std::wstring tooltip;
irr::video::SColor bgcolor;
@ -264,7 +256,7 @@ class GUIFormSpecMenu : public GUIModalMenu
rect(a_rect),
parent_button(NULL)
{
text = unescape_string(unescape_enriched(a_text));
text = unescape_enriched(a_text);
}
StaticTextSpec(const std::wstring &a_text,
const core::rect<s32> &a_rect,
@ -272,7 +264,7 @@ class GUIFormSpecMenu : public GUIModalMenu
rect(a_rect),
parent_button(a_parent_button)
{
text = unescape_string(unescape_enriched(a_text));
text = unescape_enriched(a_text);
}
std::wstring text;
core::rect<s32> rect;