aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2025-03-06 10:20:19 +0100
committerPierre Ossman <ossman@cendio.se>2025-03-13 17:13:59 +0100
commitd1fea65922416e79f2573bfc82909acc0f569977 (patch)
treeb9fc2cf8a898c6d7d29c7c8631c3cf2e41b96533
parent4ff02ae2a2280cecf183d0eb81d94757369b34ae (diff)
downloadtigervnc-d1fea65922416e79f2573bfc82909acc0f569977.tar.gz
tigervnc-d1fea65922416e79f2573bfc82909acc0f569977.zip
Handle whitespace in list parameters
-rw-r--r--common/core/Configuration.cxx7
-rw-r--r--tests/unit/parameters.cxx24
2 files changed, 31 insertions, 0 deletions
diff --git a/common/core/Configuration.cxx b/common/core/Configuration.cxx
index f5cfacb4..1a2cea88 100644
--- a/common/core/Configuration.cxx
+++ b/common/core/Configuration.cxx
@@ -562,6 +562,9 @@ bool ListParameter<ValueType>::setParam(const char* v)
for (std::string& entry : entries) {
ValueType e;
+ entry.erase(0, entry.find_first_not_of(" \f\n\r\t\v"));
+ entry.erase(entry.find_last_not_of(" \f\n\r\t\v")+1);
+
if (!decodeEntry(entry.c_str(), &e)) {
vlog.error("List parameter %s: Invalid value '%s'",
getName(), entry.c_str());
@@ -599,6 +602,8 @@ std::string ListParameter<ValueType>::getDefaultStr() const
std::string result;
for (ValueType entry : def_value) {
+ // FIXME: Might want to add a space here as well for readability,
+ // but this would sacrifice backward compatibility
if (!result.empty())
result += ',';
result += encodeEntry(entry);
@@ -613,6 +618,8 @@ std::string ListParameter<ValueType>::getValueStr() const
std::string result;
for (ValueType entry : value) {
+ // FIXME: Might want to add a space here as well for readability,
+ // but this would sacrifice backward compatibility
if (!result.empty())
result += ',';
result += encodeEntry(entry);
diff --git a/tests/unit/parameters.cxx b/tests/unit/parameters.cxx
index 03e50d8d..fb240c91 100644
--- a/tests/unit/parameters.cxx
+++ b/tests/unit/parameters.cxx
@@ -522,6 +522,14 @@ TEST(IntListParameter, strings)
strings.setParam("1,2,3,4");
data = {1, 2, 3, 4};
EXPECT_EQ(strings, data);
+
+ strings.setParam("5 , 6 , 7,8");
+ data = {5, 6, 7, 8};
+ EXPECT_EQ(strings, data);
+
+ strings.setParam("9,\n10,\t11,\t12");
+ data = {9, 10, 11, 12};
+ EXPECT_EQ(strings, data);
}
TEST(IntListParameter, minmax)
@@ -634,6 +642,14 @@ TEST(StringListParameter, strings)
strings.setParam("1,2,3,4");
data = {"1", "2", "3", "4"};
EXPECT_EQ(strings, data);
+
+ strings.setParam("5 , 6 , 7,8");
+ data = {"5", "6", "7", "8"};
+ EXPECT_EQ(strings, data);
+
+ strings.setParam("9,\n10,\t11,\t12");
+ data = {"9", "10", "11", "12"};
+ EXPECT_EQ(strings, data);
}
TEST(StringListParameter, null)
@@ -709,6 +725,14 @@ TEST(EnumListParameter, strings)
strings.setParam("a,b,c");
data = {"a", "b", "c"};
EXPECT_EQ(strings, data);
+
+ strings.setParam("c , b , a,a");
+ data = {"c", "b", "a", "a"};
+ EXPECT_EQ(strings, data);
+
+ strings.setParam("b,\na,\tc,\tb");
+ data = {"b", "a", "c", "b"};
+ EXPECT_EQ(strings, data);
}
TEST(EnumListParameter, validation)