From 2fa973ec90ea504f873b495203068734477605e8 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 31 Aug 2025 19:21:47 +0300 Subject: [PATCH] mu-label: allow more characters reduce the number of "taboo" characters in labels. update docs. --- lib/message/mu-labels.cc | 38 +++++++++++++++----------------------- man/mu-label.1.org | 11 +++++------ 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/lib/message/mu-labels.cc b/lib/message/mu-labels.cc index 6bcd9387..3254f972 100644 --- a/lib/message/mu-labels.cc +++ b/lib/message/mu-labels.cc @@ -30,7 +30,7 @@ Mu::Labels::validate_label(const std::string &label) if (label.empty()) return Err(Error{Error::Code::InvalidArgument, "labels cannot be empty"}); - else if (!g_utf8_validate(label.c_str(), label.size(), {})) // perhpps put hex in err str? + else if (!g_utf8_validate(label.c_str(), label.size(), {})) // perhaps put hex in err str? return Err(Error{Error::Code::InvalidArgument, "labels must be valid UTF-8"}); @@ -49,28 +49,18 @@ Mu::Labels::validate_label(const std::string &label) if (g_unichar_isalnum(uc)) continue; // alphanum is okay - // almost all non-ctrl ascii is allowed _except_ =,<,>,$,[] - if (uc > ' ' && uc <= '~') { - switch (uc) { - case '"': - case ',': - case '/': - case '\\': - case '*': - case '$': - return Err(Error{Error::Code::InvalidArgument, - "illegal character '{}' in label '{}'", uc, label}); - default: - break; - } - } else if (::isprint(uc)) + if (::iscntrl(uc)) return Err(Error{Error::Code::InvalidArgument, - "illegal non alpha-numeric character '{}' in label '{}'", - static_cast(uc), label}); - else + "control character {} is not allowed", + static_cast(uc)}); + if (::isblank(uc)) return Err(Error{Error::Code::InvalidArgument, - "illegal non alpha-numeric character {:#x} in label '{}'", - uc, label}); + "blank character {} is not allowed", + static_cast(uc)}); + if (uc == '"' || uc == '\'' || uc == '`' || + uc == '\\' || uc == '/' || uc == '$') + return Err(Error{Error::Code::InvalidArgument, + "character '{}' is not allowed", uc}); } return Ok(); @@ -199,7 +189,7 @@ test_parse_delta_label() g_assert_false(!!parse_delta_label("ravenking")); g_assert_false(!!parse_delta_label("+norrell strange")); - g_assert_false(!!parse_delta_label("-😨")); + g_assert_true(!!parse_delta_label("-😨")); } @@ -231,12 +221,14 @@ test_validate_label() g_assert_true(!!validate_label("ravenking")); g_assert_true(!!validate_label("@raven+king")); g_assert_true(!!validate_label("operation:mindcrime")); + g_assert_true(!!validate_label("😨")); g_assert_false(!!validate_label("norrell strange")); - g_assert_false(!!validate_label("😨")); g_assert_false(!!validate_label("")); g_assert_false(!!validate_label("+")); g_assert_false(!!validate_label("-")); + g_assert_false(!!validate_label("foo`bar")); + g_assert_false(!!validate_label("\"quoted\"")); } static void diff --git a/man/mu-label.1.org b/man/mu-label.1.org index 1bdddf78..ac83d02e 100644 --- a/man/mu-label.1.org +++ b/man/mu-label.1.org @@ -98,15 +98,14 @@ See *EXPORT FORMAT* below for details on the format. * VALID LABELS *mu* does not wish to limit your creativity, but nevertheless puts a few -restrictions on what is accepted as a label: +restrictions on what is accepted as a label. -- a *valid label character* is either a UTF-8 encoded alphanumeric character, or - any ASCII character that is not a control-character and is not one of ' ' - (SPC), ',', '"', '/', '\' '*', '$'. +- a *valid label character* is any character that is not a control-character, a + blank, or any of *'*, *"*, *`*, */*, *\*, *$* - a *valid label* consists of one or more valid label characters, the first of - which must *not* be either '+' or '-' + which must *not* be either *+* or *-* -Hence, some valid labels are: ~project-x~, ~capybara~, ~fnorb~, while some _invalid_ +Hence, some valid labels are: ~project-x~, ~c@pybara~, ~fn😃rb~, while some _invalid_ ones are: ~holiday plan~ and ~+fancy$/dinner~. * EXPORT FORMAT