From 9cb36be8ba29a0e2d23c3ba2b8059d6a317b08da Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Mon, 7 May 2018 21:23:22 +0200 Subject: [PATCH] editor: don't allow bad location id strings in particular using spaces or commas here results in invalid map files when the map is written to disk. (repoted on the forum) --- src/editor/palette/location_palette.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/editor/palette/location_palette.cpp b/src/editor/palette/location_palette.cpp index 935730dba966..4799bf30f86f 100644 --- a/src/editor/palette/location_palette.cpp +++ b/src/editor/palette/location_palette.cpp @@ -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 + 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(); } @@ -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));