From e95b16c5ca94ff060cf18bec57875e90d63f8741 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 1 Mar 2017 10:27:12 +0100 Subject: [PATCH 1/2] make hex parser strict (expecting two characters after \x) to avoid greedy parsing of trailing characters as in "\xF0\x9F\x8D\xB7abc" ==> ... + "\xB7" + "abc" not "\xB7abc" --- include/mapnik/expression_grammar_x3_def.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mapnik/expression_grammar_x3_def.hpp b/include/mapnik/expression_grammar_x3_def.hpp index 0be7fb483..23735e5de 100644 --- a/include/mapnik/expression_grammar_x3_def.hpp +++ b/include/mapnik/expression_grammar_x3_def.hpp @@ -63,7 +63,7 @@ namespace mapnik { namespace grammar { using x3::no_case; using x3::alpha; using x3::alnum; - using x3::hex; + x3::uint_parser const hex2 {}; auto do_assign = [] (auto const& ctx) { @@ -302,8 +302,8 @@ namespace mapnik { namespace grammar { x3::rule > const regex_replace_expression("regex replace expression"); // strings - auto const single_quoted_string = x3::rule {} = lit('\'') >> no_skip[*(unesc_char | ("\\x" > hex) | (char_ - '\''))] > '\''; - auto const double_quoted_string = x3::rule {} = lit('"') >> no_skip[*(unesc_char | ("\\x" > hex) | (char_ - '"'))] > '"'; + auto const single_quoted_string = x3::rule {} = lit('\'') >> no_skip[*(unesc_char | ("\\x" > hex2) | (char_ - '\''))] > '\''; + auto const double_quoted_string = x3::rule {} = lit('"') >> no_skip[*(unesc_char | ("\\x" > hex2) | (char_ - '"'))] > '"'; auto const quoted_string = x3::rule {} = single_quoted_string | double_quoted_string; auto const unquoted_ustring = x3::rule {} = no_skip[alpha > *alnum] - lit("not"); From 131f785dcee698b2bb6545511c948c45978b7303 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 1 Mar 2017 11:25:43 +0100 Subject: [PATCH 2/2] Make parsing `\xXX` format strict via hex2 parser + append UTF8 encoded `\xXX` characters directly (fixes #3631) --- include/mapnik/json/unicode_string_grammar_x3_def.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/mapnik/json/unicode_string_grammar_x3_def.hpp b/include/mapnik/json/unicode_string_grammar_x3_def.hpp index d58293cf3..788ea7247 100644 --- a/include/mapnik/json/unicode_string_grammar_x3_def.hpp +++ b/include/mapnik/json/unicode_string_grammar_x3_def.hpp @@ -48,6 +48,8 @@ void push_utf8_impl(std::string & str, uchar code_point) } } +auto push_char = [](auto const& ctx) { _val(ctx).push_back(_attr(ctx));}; + auto push_utf8 = [](auto const& ctx) { detail::push_utf8_impl(_val(ctx), _attr(ctx));}; auto push_esc = [] (auto const& ctx) @@ -79,10 +81,10 @@ auto push_esc = [] (auto const& ctx) using x3::lit; using x3::char_; -using x3::hex; using x3::eol; using x3::no_skip; +x3::uint_parser const hex2 {}; x3::uint_parser const hex4 {}; x3::uint_parser const hex8 {}; @@ -95,7 +97,7 @@ x3::rule const escaped("Escaped Characted"); auto unicode_string_def = double_quoted ; auto const escaped_def = lit('\\') > - ((lit('x') > hex[push_utf8]) + ((lit('x') > hex2[push_char]) | (lit('u') > hex4[push_utf8]) |