# HG changeset patch # User David Demelier # Date 1567280642 -7200 # Node ID cb7532847b08613919a9e80fc6e15fbec4448ed8 # Parent 54496ac5164975d389c8e7d1977f0d8c0d9a9b06 irccd: fix invalid template, closes #2250 diff -r 54496ac51649 -r cb7532847b08 CHANGES.md --- a/CHANGES.md Fri Aug 30 21:03:00 2019 +0200 +++ b/CHANGES.md Sat Aug 31 21:44:02 2019 +0200 @@ -1,6 +1,12 @@ IRC Client Daemon CHANGES ========================= +irccd 3.0.1 2019-09-01 +---------------------- + +- Fixed an invalid template escape sequence (#2250), +- Updated the default configuration files (#2249). + irccd 3.0.0 2019-08-15 ---------------------- diff -r 54496ac51649 -r cb7532847b08 doc/examples/irccd.conf.sample --- a/doc/examples/irccd.conf.sample Fri Aug 30 21:03:00 2019 +0200 +++ b/doc/examples/irccd.conf.sample Sat Aug 31 21:44:02 2019 +0200 @@ -60,7 +60,7 @@ # command-char = "!" # (string) the prefix for invoking special commands (Optional, default: !), # ssl = false # (bool) enable or disable SSL (Optional, default: false), # auto-reconnect = true # (bool) enable reconnection after failure (Optional, default: true), -# auto-reconnect-timeout = 5 # (int) number of seconds to wait before retrying (Optional, default: 30). +# auto-reconnect-delay = 5 # (int) number of seconds to wait before retrying (Optional, default: 30). [server] name = "localhost" @@ -139,9 +139,9 @@ # To format general messages: # # [templates] -# debug = "DD #{messages} # (string) debug messages. -# info = "II #{messages} # (string) information messages. -# warning = "WW #{messages} # (string) warning messages. +# debug = "DD #{message} # (string) debug messages. +# info = "II #{message} # (string) information messages. +# warning = "WW #{message} # (string) warning messages. # # To format specific plugins: # diff -r 54496ac51649 -r cb7532847b08 libirccd/irccd/string_util.cpp --- a/libirccd/irccd/string_util.cpp Fri Aug 30 21:03:00 2019 +0200 +++ b/libirccd/irccd/string_util.cpp Sat Aug 31 21:44:02 2019 +0200 @@ -327,7 +327,7 @@ std::ostringstream oss; for (auto it = text.cbegin(), end = text.cend(); it != end; ) { - auto token = *it; + const auto token = *it; // Is the current character a reserved token or not? if (!is_reserved(token)) { @@ -341,36 +341,22 @@ continue; } - // The token is declaring a template variable, substitute it. - if (*it == '{') { - oss << substitute(++it, end, token, params); - continue; - } + /* + * ## -> # + * #{key} -> value (if key == value) + * ##{key} -> #{key} + * ###{key} -> #value (if key == value) + * @#{key} -> @vlalue (if key == value) + */ - /* - * If the next token is different from the previous one, just let the - * next iteration parse the string because we can have the following - * constructs. - * - * "@#{var}" -> "@value" - */ - if (*it != token) { + if (*it == '{') + oss << substitute(++it, end, token, params); + else { + if (*it == token) + ++it; + oss << token; - continue; } - - /* - * Write the token only if it's not a variable because at this step we - * may have the following constructs. - * - * "##" -> "##" - * "##hello" -> "##hello" - * "##{hello}" -> "#{hello}" - */ - if (++it == end) - oss << token << token; - else if (*it == '{') - oss << token; } return oss.str(); diff -r 54496ac51649 -r cb7532847b08 man/irccd-templates.7 --- a/man/irccd-templates.7 Fri Aug 30 21:03:00 2019 +0200 +++ b/man/irccd-templates.7 Sat Aug 31 21:44:02 2019 +0200 @@ -189,7 +189,8 @@ Valid constructs: .Bl -tag -width 20n -offset Ds .It #{target}, welcome -if target is set to "irccd", becomes "irccd, welcome". +if target is set to "irccd", becomes +.Dq "irccd, welcome" . .It @{red}#{target} if target is specified, it is written in red. .El @@ -197,13 +198,21 @@ Invalid or literals constructs: .Bl -tag -width 20n -offset Ds .It ##{target} -will output "#{target}". -.It ## -will output "##". +will output +.Dq #{target} . +.It abc##xyz +will output +.Dq abc#xyz . .It #target -will output "#target". +will output +.Dq #target . .It #{target will cause an error. +.It @#{message} +will output +.Dq @bar +if message keyword is set to +.Dq bar . .El .Pp Colors & attributes: diff -r 54496ac51649 -r cb7532847b08 tests/src/libirccd/string-util/main.cpp --- a/tests/src/libirccd/string-util/main.cpp Fri Aug 30 21:03:00 2019 +0200 +++ b/tests/src/libirccd/string-util/main.cpp Sat Aug 31 21:44:02 2019 +0200 @@ -51,7 +51,7 @@ BOOST_TEST(string_util::format("#") == "#"); BOOST_TEST(string_util::format(" # ") == " # "); BOOST_TEST(string_util::format("#@") == "#@"); - BOOST_TEST(string_util::format("##") == "##"); + BOOST_TEST(string_util::format("##") == "#"); BOOST_TEST(string_util::format("#!") == "#!"); BOOST_TEST(string_util::format("##{target}") == "#{target}"); BOOST_TEST(string_util::format("@#{target}", params) == "@hello"); @@ -152,6 +152,17 @@ BOOST_TEST(expected == result); } +BOOST_AUTO_TEST_CASE(fix_2250) +{ + string_util::subst params; + + params.keywords.insert({"target", "irccd"}); + + BOOST_TEST(string_util::format("abc##xyz") == "abc#xyz"); + BOOST_TEST(string_util::format("abc###xyz") == "abc##xyz"); + BOOST_TEST(string_util::format("###{target}", params) == "#irccd"); +} + BOOST_AUTO_TEST_SUITE_END() /*