summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-06-14 10:09:22 +0200
committerLennart Poettering <lennart@poettering.net>2023-06-14 10:15:41 +0200
commitd0a6d7c4d1285d6af2be299a466c964f0c5991a2 (patch)
treefbca2ed76e47cf593c505a7597c00b0031f6f473
parentMerge pull request #26728 from keszybz/meson-update (diff)
downloadsystemd-d0a6d7c4d1285d6af2be299a466c964f0c5991a2.tar.xz
systemd-d0a6d7c4d1285d6af2be299a466c964f0c5991a2.zip
time-util,socket: accept both kinds of unicode µ symbols
Apparently there are two µ symbols, accept both when parsing. One is the greek small letter mu (μ) the other is the micro sign (µ). Unicode recommendation considers both equivalent, and says use of greek small letter mu is preferred. See: https://www.unicode.org/reports/tr25 Hence accept both when parsing. Inspired by: #28029
-rw-r--r--src/basic/time-util.c10
-rw-r--r--src/core/socket.c2
-rw-r--r--src/test/test-time-util.c4
3 files changed, 10 insertions, 6 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index f124e6f016..0ab2a81059 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1046,7 +1046,8 @@ static const char* extract_multiplier(const char *p, usec_t *ret) {
{ "y", USEC_PER_YEAR },
{ "usec", 1ULL },
{ "us", 1ULL },
- { "µs", 1ULL },
+ { "μs", 1ULL }, /* U+03bc (aka GREEK SMALL LETTER MU) */
+ { "µs", 1ULL }, /* U+b5 (aka MICRO SIGN) */
};
assert(p);
@@ -1224,7 +1225,8 @@ static const char* extract_nsec_multiplier(const char *p, nsec_t *ret) {
{ "y", NSEC_PER_YEAR },
{ "usec", NSEC_PER_USEC },
{ "us", NSEC_PER_USEC },
- { "µs", NSEC_PER_USEC },
+ { "μs", NSEC_PER_USEC }, /* U+03bc (aka GREEK LETTER MU) */
+ { "µs", NSEC_PER_USEC }, /* U+b5 (aka MICRO SIGN) */
{ "nsec", 1ULL },
{ "ns", 1ULL },
{ "", 1ULL }, /* default is nsec */
@@ -1701,9 +1703,9 @@ TimestampStyle timestamp_style_from_string(const char *s) {
t = (TimestampStyle) string_table_lookup(timestamp_style_table, ELEMENTSOF(timestamp_style_table), s);
if (t >= 0)
return t;
- if (streq_ptr(s, "µs"))
+ if (STRPTR_IN_SET(s, "µs", "μs")) /* acccept both µ symbols in unicode, i.e. micro symbol + greek small letter mu. */
return TIMESTAMP_US;
- if (streq_ptr(s, "µs+utc"))
+ if (STRPTR_IN_SET(s, "µs+utc", "μs+utc"))
return TIMESTAMP_US_UTC;
return t;
}
diff --git a/src/core/socket.c b/src/core/socket.c
index 8e7797139b..e4c1f5a793 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -3519,7 +3519,7 @@ SocketTimestamping socket_timestamping_from_string_harder(const char *p) {
* too. */
if (streq(p, "nsec"))
return SOCKET_TIMESTAMPING_NS;
- if (STR_IN_SET(p, "usec", "µs"))
+ if (STR_IN_SET(p, "usec", "µs", "μs")) /* Accept both small greek letter mu + micro sign unicode codepoints */
return SOCKET_TIMESTAMPING_US;
r = parse_boolean(p);
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index 235c6cf164..a67bfc8734 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -35,7 +35,9 @@ TEST(parse_sec) {
assert_se(u == 700 * USEC_PER_MSEC);
assert_se(parse_sec("23us", &u) >= 0);
assert_se(u == 23);
- assert_se(parse_sec("23µs", &u) >= 0);
+ assert_se(parse_sec("23μs", &u) >= 0); /* greek small letter mu */
+ assert_se(u == 23);
+ assert_se(parse_sec("23µs", &u) >= 0); /* micro symbol */
assert_se(u == 23);
assert_se(parse_sec("infinity", &u) >= 0);
assert_se(u == USEC_INFINITY);