Skip to content

Commit 4d9dbce

Browse files
committedMay 7, 2016
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.
1 parent d5c3db9 commit 4d9dbce

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed
 

‎src/guiFormSpecMenu.cpp

+20-17
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
422422
if (selected == "true")
423423
fselected = true;
424424

425-
std::wstring wlabel = utf8_to_wide(label);
425+
std::wstring wlabel = utf8_to_wide(unescape_string(label));
426426

427427
core::rect<s32> rect = core::rect<s32>(
428428
pos.X, pos.Y + ((imgsize.Y/2) - m_btn_height),
@@ -618,7 +618,7 @@ void GUIFormSpecMenu::parseButton(parserData* data,std::string element,
618618
if(!data->explicit_size)
619619
warningstream<<"invalid use of button without a size[] element"<<std::endl;
620620

621-
std::wstring wlabel = utf8_to_wide(label);
621+
std::wstring wlabel = utf8_to_wide(unescape_string(label));
622622

623623
FieldSpec spec(
624624
name,
@@ -752,7 +752,7 @@ void GUIFormSpecMenu::parseTable(parserData* data,std::string element)
752752
spec.ftype = f_Table;
753753

754754
for (unsigned int i = 0; i < items.size(); ++i) {
755-
items[i] = unescape_string(unescape_enriched(items[i]));
755+
items[i] = unescape_enriched(unescape_string(items[i]));
756756
}
757757

758758
//now really show table
@@ -824,7 +824,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element)
824824
spec.ftype = f_Table;
825825

826826
for (unsigned int i = 0; i < items.size(); ++i) {
827-
items[i] = unescape_string(unescape_enriched(items[i]));
827+
items[i] = unescape_enriched(unescape_string(items[i]));
828828
}
829829

830830
//now really show list
@@ -895,7 +895,7 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
895895
}
896896

897897
for (unsigned int i=0; i < items.size(); i++) {
898-
e->addItem(unescape_string(unescape_enriched(
898+
e->addItem(unescape_enriched(unescape_string(
899899
utf8_to_wide(items[i]))).c_str());
900900
}
901901

@@ -945,7 +945,7 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
945945

946946
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
947947

948-
std::wstring wlabel = utf8_to_wide(label);
948+
std::wstring wlabel = utf8_to_wide(unescape_string(label));
949949

950950
FieldSpec spec(
951951
name,
@@ -1009,12 +1009,12 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
10091009
default_val = m_form_src->resolveText(default_val);
10101010

10111011

1012-
std::wstring wlabel = utf8_to_wide(label);
1012+
std::wstring wlabel = utf8_to_wide(unescape_string(label));
10131013

10141014
FieldSpec spec(
10151015
name,
10161016
wlabel,
1017-
utf8_to_wide(default_val),
1017+
utf8_to_wide(unescape_string(default_val)),
10181018
258+m_fields.size()
10191019
);
10201020

@@ -1105,12 +1105,12 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,
11051105
default_val = m_form_src->resolveText(default_val);
11061106

11071107

1108-
std::wstring wlabel = utf8_to_wide(label);
1108+
std::wstring wlabel = utf8_to_wide(unescape_string(label));
11091109

11101110
FieldSpec spec(
11111111
name,
11121112
wlabel,
1113-
utf8_to_wide(default_val),
1113+
utf8_to_wide(unescape_string(default_val)),
11141114
258+m_fields.size()
11151115
);
11161116

@@ -1218,7 +1218,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
12181218
// in the integer cases: 0.4 is not exactly
12191219
// representable in binary floating point.
12201220
s32 posy = pos.Y + ((float)i) * spacing.Y * 2.0 / 5.0;
1221-
std::wstring wlabel = utf8_to_wide(lines[i]);
1221+
std::wstring wlabel = utf8_to_wide(unescape_string(lines[i]));
12221222
core::rect<s32> rect = core::rect<s32>(
12231223
pos.X, posy - m_btn_height,
12241224
pos.X + m_font->getDimension(wlabel.c_str()).Width,
@@ -1250,8 +1250,8 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element)
12501250
((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
12511251
{
12521252
std::vector<std::string> v_pos = split(parts[0],',');
1253-
std::wstring text = unescape_string(
1254-
unescape_enriched(utf8_to_wide(parts[1])));
1253+
std::wstring text = unescape_enriched(
1254+
unescape_string(utf8_to_wide(parts[1])));
12551255

12561256
MY_CHECKPOS("vertlabel",1);
12571257

@@ -1339,7 +1339,7 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
13391339
image_name = unescape_string(image_name);
13401340
pressed_image_name = unescape_string(pressed_image_name);
13411341

1342-
std::wstring wlabel = utf8_to_wide(label);
1342+
std::wstring wlabel = utf8_to_wide(unescape_string(label));
13431343

13441344
FieldSpec spec(
13451345
name,
@@ -1437,7 +1437,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element)
14371437
e->setNotClipped(true);
14381438

14391439
for (unsigned int i = 0; i < buttons.size(); i++) {
1440-
e->addTab(unescape_string(unescape_enriched(
1440+
e->addTab(unescape_enriched(unescape_string(
14411441
utf8_to_wide(buttons[i]))).c_str(), -1);
14421442
}
14431443

@@ -1473,6 +1473,9 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
14731473
std::string name = parts[3];
14741474
std::string label = parts[4];
14751475

1476+
label = unescape_string(label);
1477+
item_name = unescape_string(item_name);
1478+
14761479
MY_CHECKPOS("itemimagebutton",0);
14771480
MY_CHECKGEOM("itemimagebutton",1);
14781481

@@ -1611,14 +1614,14 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, std::string element)
16111614
std::vector<std::string> parts = split(element,';');
16121615
if (parts.size() == 2) {
16131616
std::string name = parts[0];
1614-
m_tooltips[name] = TooltipSpec(parts[1],
1617+
m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
16151618
m_default_tooltip_bgcolor, m_default_tooltip_color);
16161619
return;
16171620
} else if (parts.size() == 4) {
16181621
std::string name = parts[0];
16191622
video::SColor tmp_color1, tmp_color2;
16201623
if ( parseColorString(parts[2], tmp_color1, false) && parseColorString(parts[3], tmp_color2, false) ) {
1621-
m_tooltips[name] = TooltipSpec(parts[1],
1624+
m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
16221625
tmp_color1, tmp_color2);
16231626
return;
16241627
}

‎src/guiFormSpecMenu.h

+5-13
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,6 @@ class GUIFormSpecMenu : public GUIModalMenu
192192
bool scale;
193193
};
194194

195-
/* The responsibility of unescaping the strings has been shifted
196-
* from the formspec parsing methods to the draw methods.
197-
* There still are a few exceptions:
198-
* - Vertical label, because it modifies the string by inserting
199-
* '\n' between each character,
200-
* - Tab header, because it gives the string immediately to
201-
* Irrlicht and we can't unescape it later.
202-
*/
203195
struct FieldSpec
204196
{
205197
FieldSpec()
@@ -210,8 +202,8 @@ class GUIFormSpecMenu : public GUIModalMenu
210202
fname(name),
211203
fid(id)
212204
{
213-
flabel = unescape_string(unescape_enriched(label));
214-
fdefault = unescape_string(unescape_enriched(default_text));
205+
flabel = unescape_enriched(label);
206+
fdefault = unescape_enriched(default_text);
215207
send = false;
216208
ftype = f_Unknown;
217209
is_exit = false;
@@ -247,7 +239,7 @@ class GUIFormSpecMenu : public GUIModalMenu
247239
bgcolor(a_bgcolor),
248240
color(a_color)
249241
{
250-
tooltip = unescape_string(unescape_enriched(utf8_to_wide(a_tooltip)));
242+
tooltip = unescape_enriched(utf8_to_wide(a_tooltip));
251243
}
252244
std::wstring tooltip;
253245
irr::video::SColor bgcolor;
@@ -264,15 +256,15 @@ class GUIFormSpecMenu : public GUIModalMenu
264256
rect(a_rect),
265257
parent_button(NULL)
266258
{
267-
text = unescape_string(unescape_enriched(a_text));
259+
text = unescape_enriched(a_text);
268260
}
269261
StaticTextSpec(const std::wstring &a_text,
270262
const core::rect<s32> &a_rect,
271263
gui::IGUIButton *a_parent_button):
272264
rect(a_rect),
273265
parent_button(a_parent_button)
274266
{
275-
text = unescape_string(unescape_enriched(a_text));
267+
text = unescape_enriched(a_text);
276268
}
277269
std::wstring text;
278270
core::rect<s32> rect;

0 commit comments

Comments
 (0)
Please sign in to comment.