test: escape '+' from uname -r before using in regex via '=~'

It will otherwise interpret characters such as '+' as if they
were regex, and break matching.

For example TEST-71-HOSTNAME started failing when
uname -r started including a '+':

FAIL: 'Kernel: Linux 6.12.33+deb13-amd64' not found in:
 Static hostname: host
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: e6471c1f95ab49098827498ed816cdf7
         Boot ID: 231da987f64d4af59f2076fbb638c611
  Virtualization: kvm
Operating System: Debian GNU/Linux 13 (trixie)
          Kernel: Linux 6.12.33+deb13-amd64
    Architecture: x86-64
This commit is contained in:
Luca Boccassi
2025-06-24 13:07:11 +01:00
committed by Yu Watanabe
parent 736b627775
commit a0dfb02456
2 changed files with 3 additions and 3 deletions

View File

@@ -163,11 +163,11 @@ EOF
udevadm control --reload
output=$(udevadm test --action add /sys/class/net/test1)
assert_in "LINK_VERSION=$(uname -r)" "$output"
assert_in "LINK_VERSION=$(uname -r | sed 's/\+/\\+/g')" "$output"
udevadm trigger --settle --action add /sys/class/net/test1
output=$(udevadm info --query property /sys/class/net/test1)
assert_in "LINK_VERSION=$(uname -r)" "$output"
assert_in "LINK_VERSION=$(uname -r | sed 's/\+/\\+/g')" "$output"
# test for constant properties
cat >/run/systemd/network/10-test.link.d/13-override.conf <<EOF

View File

@@ -31,7 +31,7 @@ testcase_hostname() {
if [[ -n "$orig" ]]; then
assert_in "Static hostname: $orig" "$(hostnamectl)"
fi
assert_in "Kernel: $(uname -s) $(uname -r)" "$(hostnamectl)"
assert_in "Kernel: $(uname -s) $(uname -r | sed 's/\+/\\+/g')" "$(hostnamectl)"
# change hostname
assert_rc 0 hostnamectl set-hostname testhost