diff --git a/data/blueprints/library/test/ecosystem/golden/gui_quantum-4-query.csv b/data/blueprints/library/test/ecosystem/golden/gui_quantum-4-query.csv index e9d422551..811f7b3b0 100644 --- a/data/blueprints/library/test/ecosystem/golden/gui_quantum-4-query.csv +++ b/data/blueprints/library/test/ecosystem/golden/gui_quantum-4-query.csv @@ -2,5 +2,5 @@ -,,{givename name="foo dumper"} -,,{givename name="foo"} +,,"{givename name=""foo dumper""}" +,,"{givename name=""foo""}" diff --git a/plugins/blueprint.cpp b/plugins/blueprint.cpp index 330b61729..509b1e6bc 100644 --- a/plugins/blueprint.cpp +++ b/plugins/blueprint.cpp @@ -5,8 +5,6 @@ * Written by cdombroski. */ -#include -#include #include #include @@ -1011,11 +1009,23 @@ static const char * get_tile_zone(const df::coord &pos, return add_expansion_syntax(zone, get_zone_keys(zone)); } -static string csv_sanitize(const string &str) { - static const std::regex pattern("\""); - static const string replacement("\"\""); +// surrounds the given string in quotes and replaces internal double quotes (") +// with double double quotes ("") (as per the csv spec) +static string csv_quote(const string &str) { + std::ostringstream outstr; + outstr << "\""; + + size_t start = 0; + auto end = str.find('"'); + while (end != std::string::npos) { + outstr << str.substr(start, end - start); + outstr << "\"\""; + start = end + 1; + end = str.find('"', start); + } + outstr << str.substr(start, end) << "\""; - return std::regex_replace(str, pattern, replacement); + return outstr.str(); } static const char * get_tile_query(const df::coord &pos, @@ -1042,11 +1052,11 @@ static const char * get_tile_query(const df::coord &pos, std::ostringstream str; if (bld_name.size()) - str << "{givename name=\"" << csv_sanitize(bld_name) << "\"}"; + str << "{givename name=" + csv_quote(bld_name) + "}"; if (zone_name.size()) - str << "{namezone name=\"" << csv_sanitize(zone_name) << "\"}"; + str << "{namezone name=" + csv_quote(zone_name) + "}"; - return cache(str); + return cache(csv_quote(str.str())); } static const char * get_tile_rooms(const df::coord &, const tile_context &ctx) { diff --git a/test/quickfort/ecosystem.lua b/test/quickfort/ecosystem.lua index 663bc353b..27dddc5d5 100644 --- a/test/quickfort/ecosystem.lua +++ b/test/quickfort/ecosystem.lua @@ -444,7 +444,7 @@ function extra_fns.gui_quantum(pos) view:onInput({_STRING=string.byte('f')}) view:onInput({_STRING=string.byte('o')}) view:onInput({_STRING=string.byte('o')}) - view:onInput({SELECT=true}) + send_keys('SELECT') -- rotate the dump direction to the south send_keys('CUSTOM_D') view:onRender()