File 050-Validation-allow-spaces-disallow-slashes.patch of Package virt-manager

Subject: Validation: allow spaces, disallow slashes
From: AbhinavTiruvee ranjaniabhinav@gmail.com Mon Apr 7 18:05:41 2025 -0500
Date: Tue Apr 22 12:11:00 2025 +0200:
Git: 237896029d668543465b4566d0ea880d468c7058

Libvirt permits spaces in object names but rejects the ‘/’ character.
This change aligns our validator with libvirt’s behavior (and QEMU’s),
preventing names with '/' while still allowing human‑friendly
names with spaces.

Fixes: #740

diff --git a/tests/test_xmlparse.py b/tests/test_xmlparse.py
index c4107f932..898fc55c3 100644
--- a/tests/test_xmlparse.py
+++ b/tests/test_xmlparse.py
@@ -1011,7 +1011,9 @@ def testXMLBuilderCoverage():
         virtinst.DeviceDisk.validate_generic_name("objtype", None)
 
     with pytest.raises(ValueError):
-        virtinst.DeviceDisk.validate_generic_name("objtype", "foo bar")
+        virtinst.DeviceDisk.validate_generic_name("objtype", "foo/bar")
+
+    assert virtinst.DeviceDisk.validate_generic_name("objtype", "foo bar") is None
 
     # Test property __repr__ for code coverage
     assert "DeviceAddress" in str(virtinst.DeviceDisk.address)
diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py
index 64ea25e1b..8ec18a7a7 100644
--- a/virtinst/xmlbuilder.py
+++ b/virtinst/xmlbuilder.py
@@ -511,9 +511,8 @@ class XMLBuilder(object):
 
     @staticmethod
     def validate_generic_name(name_label, val):
-        # Rather than try and match libvirt's regex, just forbid things we
-        # know don't work
-        forbid = [" "]
+        # Only character that shouldn't work is '/', matching QEMU
+        forbid = ["/"]
         if not val:
             # translators: value is a generic object type name
             raise ValueError(_("A name must be specified for the %s") %
openSUSE Build Service is sponsored by