mu-label: allow more characters
reduce the number of "taboo" characters in labels. update docs.
This commit is contained in:
@ -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<char>(uc), label});
|
||||
else
|
||||
"control character {} is not allowed",
|
||||
static_cast<int>(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<int>(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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user