summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/basic/string-util.c15
-rw-r--r--src/basic/string-util.h2
-rw-r--r--src/sysupdate/meson.build2
-rw-r--r--src/sysupdate/sysupdate-pattern.c1
-rw-r--r--src/sysupdate/sysupdate-transfer.c1
-rw-r--r--src/sysupdate/sysupdate-util.c13
-rw-r--r--src/sysupdate/sysupdate-util.h6
-rw-r--r--src/test/test-string-util.c10
8 files changed, 27 insertions, 23 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index 41d264318a..1eedcb66f7 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -16,6 +16,7 @@
#include "macro.h"
#include "memory-util.h"
#include "memstream-util.h"
+#include "path-util.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
@@ -1296,3 +1297,17 @@ char *startswith_strv(const char *string, char **strv) {
return found;
}
+
+bool version_is_valid(const char *s) {
+ if (isempty(s))
+ return false;
+
+ if (!filename_part_is_valid(s))
+ return false;
+
+ /* This is a superset of the characters used by semver. We additionally allow "," and "_". */
+ if (!in_charset(s, ALPHANUMERICAL ".,_-+"))
+ return false;
+
+ return true;
+}
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index b5028c9e00..0ff5b46bba 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -275,3 +275,5 @@ char *startswith_strv(const char *string, char **strv);
#define STARTSWITH_SET(p, ...) \
startswith_strv(p, STRV_MAKE(__VA_ARGS__))
+
+bool version_is_valid(const char *s);
diff --git a/src/sysupdate/meson.build b/src/sysupdate/meson.build
index 2f8c2305da..1bd6bbf9a9 100644
--- a/src/sysupdate/meson.build
+++ b/src/sysupdate/meson.build
@@ -15,8 +15,6 @@ systemd_sysupdate_sources = files(
'sysupdate-transfer.h',
'sysupdate-update-set.c',
'sysupdate-update-set.h',
- 'sysupdate-util.c',
- 'sysupdate-util.h',
'sysupdate.c',
'sysupdate.h',
)
diff --git a/src/sysupdate/sysupdate-pattern.c b/src/sysupdate/sysupdate-pattern.c
index 6d9c8d8f8b..c9e2067c58 100644
--- a/src/sysupdate/sysupdate-pattern.c
+++ b/src/sysupdate/sysupdate-pattern.c
@@ -8,7 +8,6 @@
#include "stdio-util.h"
#include "string-util.h"
#include "sysupdate-pattern.h"
-#include "sysupdate-util.h"
typedef enum PatternElementType {
PATTERN_LITERAL,
diff --git a/src/sysupdate/sysupdate-transfer.c b/src/sysupdate/sysupdate-transfer.c
index bbc3a5bcaa..dd2b1e45eb 100644
--- a/src/sysupdate/sysupdate-transfer.c
+++ b/src/sysupdate/sysupdate-transfer.c
@@ -24,7 +24,6 @@
#include "sysupdate-pattern.h"
#include "sysupdate-resource.h"
#include "sysupdate-transfer.h"
-#include "sysupdate-util.h"
#include "sysupdate.h"
#include "tmpfile-util.h"
#include "web-util.h"
diff --git a/src/sysupdate/sysupdate-util.c b/src/sysupdate/sysupdate-util.c
index c7a23015ce..eacc592f62 100644
--- a/src/sysupdate/sysupdate-util.c
+++ b/src/sysupdate/sysupdate-util.c
@@ -2,16 +2,3 @@
#include "path-util.h"
#include "sysupdate-util.h"
-
-bool version_is_valid(const char *s) {
- if (isempty(s))
- return false;
-
- if (!filename_is_valid(s))
- return false;
-
- if (!in_charset(s, ALPHANUMERICAL ".,_-+"))
- return false;
-
- return true;
-}
diff --git a/src/sysupdate/sysupdate-util.h b/src/sysupdate/sysupdate-util.h
deleted file mode 100644
index afa3a9d498..0000000000
--- a/src/sysupdate/sysupdate-util.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-#include <stdbool.h>
-
-bool version_is_valid(const char *s);
diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c
index 2d3e40321e..e8fcc5a13c 100644
--- a/src/test/test-string-util.c
+++ b/src/test/test-string-util.c
@@ -1264,4 +1264,14 @@ TEST(strstrafter) {
assert_se(!strstrafter(buffer, "-"));
}
+TEST(version_is_valid) {
+ assert_se(!version_is_valid(NULL));
+ assert_se(!version_is_valid(""));
+ assert_se(version_is_valid("0"));
+ assert_se(version_is_valid("5"));
+ assert_se(version_is_valid("999999"));
+ assert_se(version_is_valid("999999.5"));
+ assert_se(version_is_valid("6.2.12-300.fc38.x86_64"));
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);