Skip to content

Commit

Permalink
editor: don't allow bad location id strings
Browse files Browse the repository at this point in the history
in particular using spaces or commas here results in invalid map files when the map is written to disk. (repoted on the forum)
  • Loading branch information
gfgtdf committed May 7, 2018
1 parent 500f510 commit 9cb36be
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/editor/palette/location_palette.cpp
Expand Up @@ -21,11 +21,15 @@
#include "font/standard_colors.hpp"
#include "tooltips.hpp"

#include "editor/editor_common.hpp"
#include "editor/toolkit/editor_toolkit.hpp"
#include "gui/dialogs/edit_text.hpp"
#include "gui/dialogs/transient_message.hpp"

#include "formula/string_utils.hpp"

#include <boost/regex.hpp>

static bool is_positive_integer(const std::string& str) {
return str != "0" && std::find_if(str.begin(), str.end(), [](char c) { return !std::isdigit(c); }) == str.end();
}
Expand Down Expand Up @@ -259,7 +263,18 @@ void location_palette::adjust_size(const SDL_Rect& target)
button_add_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Add"), [this]() {
std::string newid;
if (gui2::dialogs::edit_text::execute(_("New Location Identifier"), "", newid)) {
add_item(newid);
static const boost::regex valid_id("[a-zA-Z_]+");
if(boost::regex_match(newid, valid_id)) {
add_item(newid);
}
else {
gui2::show_transient_message(
_("Error"),
_("Invalid location id")
);
//TODO: a user visible messae would be nice.
ERR_ED << "entered invalid location id\n";
}
}
}));
button_delete_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Delete"), nullptr));
Expand Down

0 comments on commit 9cb36be

Please sign in to comment.