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())
|
if (label.empty())
|
||||||
return Err(Error{Error::Code::InvalidArgument,
|
return Err(Error{Error::Code::InvalidArgument,
|
||||||
"labels cannot be empty"});
|
"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,
|
return Err(Error{Error::Code::InvalidArgument,
|
||||||
"labels must be valid UTF-8"});
|
"labels must be valid UTF-8"});
|
||||||
|
|
||||||
@ -49,28 +49,18 @@ Mu::Labels::validate_label(const std::string &label)
|
|||||||
if (g_unichar_isalnum(uc))
|
if (g_unichar_isalnum(uc))
|
||||||
continue; // alphanum is okay
|
continue; // alphanum is okay
|
||||||
|
|
||||||
// almost all non-ctrl ascii is allowed _except_ =,<,>,$,[]
|
if (::iscntrl(uc))
|
||||||
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))
|
|
||||||
return Err(Error{Error::Code::InvalidArgument,
|
return Err(Error{Error::Code::InvalidArgument,
|
||||||
"illegal non alpha-numeric character '{}' in label '{}'",
|
"control character {} is not allowed",
|
||||||
static_cast<char>(uc), label});
|
static_cast<int>(uc)});
|
||||||
else
|
if (::isblank(uc))
|
||||||
return Err(Error{Error::Code::InvalidArgument,
|
return Err(Error{Error::Code::InvalidArgument,
|
||||||
"illegal non alpha-numeric character {:#x} in label '{}'",
|
"blank character {} is not allowed",
|
||||||
uc, label});
|
static_cast<int>(uc)});
|
||||||
|
if (uc == '"' || uc == '\'' || uc == '`' ||
|
||||||
|
uc == '\\' || uc == '/' || uc == '$')
|
||||||
|
return Err(Error{Error::Code::InvalidArgument,
|
||||||
|
"character '{}' is not allowed", uc});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
@ -199,7 +189,7 @@ test_parse_delta_label()
|
|||||||
|
|
||||||
g_assert_false(!!parse_delta_label("ravenking"));
|
g_assert_false(!!parse_delta_label("ravenking"));
|
||||||
g_assert_false(!!parse_delta_label("+norrell strange"));
|
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("ravenking"));
|
||||||
g_assert_true(!!validate_label("@raven+king"));
|
g_assert_true(!!validate_label("@raven+king"));
|
||||||
g_assert_true(!!validate_label("operation:mindcrime"));
|
g_assert_true(!!validate_label("operation:mindcrime"));
|
||||||
|
g_assert_true(!!validate_label("😨"));
|
||||||
|
|
||||||
g_assert_false(!!validate_label("norrell strange"));
|
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("+"));
|
||||||
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
|
static void
|
||||||
|
|||||||
@ -98,15 +98,14 @@ See *EXPORT FORMAT* below for details on the format.
|
|||||||
* VALID LABELS
|
* VALID LABELS
|
||||||
|
|
||||||
*mu* does not wish to limit your creativity, but nevertheless puts a few
|
*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
|
- a *valid label character* is any character that is not a control-character, a
|
||||||
any ASCII character that is not a control-character and is not one of ' '
|
blank, or any of *'*, *"*, *`*, */*, *\*, *$*
|
||||||
(SPC), ',', '"', '/', '\' '*', '$'.
|
|
||||||
- a *valid label* consists of one or more valid label characters, the first 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~.
|
ones are: ~holiday plan~ and ~+fancy$/dinner~.
|
||||||
|
|
||||||
* EXPORT FORMAT
|
* EXPORT FORMAT
|
||||||
|
|||||||
Reference in New Issue
Block a user