[Kimchi-devel] [PATCH] Github issue #306: Creating a guest OS whose name contain spaces causes it to fail.

Otavio R. Piske angusyoung at gmail.com
Wed Jan 22 21:01:25 UTC 2014


From: "Otavio R. Piske" <angusyoung at gmail.com>

Kimchi fails to start the guest OS if the user names it with spaces. As pointed in the issue #306, other VM management interfaces prevent the user from creating a guest OS if the name contain invalid characters.

This patch adds a validation logic that prevents the user from naming a Guest OS with anything other than alphanumeric chars, '-', '.' or '_'.

Signed-off-by: Otavio R. Piske <angusyoung at gmail.com>
---
 ui/js/src/kimchi.guest_add_main.js |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/ui/js/src/kimchi.guest_add_main.js b/ui/js/src/kimchi.guest_add_main.js
index 2085562..b65f2ef 100644
--- a/ui/js/src/kimchi.guest_add_main.js
+++ b/ui/js/src/kimchi.guest_add_main.js
@@ -53,6 +53,18 @@ kimchi.guest_add_main = function() {
         if (!$('input[name=template]:checked', '#templateTile').val()) {
             return false;
         }
+
+        var name = $('input[name=name]', '#form-vm-add').val();
+
+        /* This regex should match anything that it's not an alphanumeric
+         * string, -, ., or _.
+         */
+        var invalidChars = /[^A-Za-z0-9\-\.\_]/g;
+
+        if (invalidChars.exec(name)) {
+            return false;
+        }
+
         return true;
     }
 
@@ -60,6 +72,9 @@ kimchi.guest_add_main = function() {
         if (validateForm()) {
             $('#vm-doAdd').removeAttr('disabled');
         }
+        else {
+             $('#vm-doAdd').attr('disabled', 'disabled');
+        }
     });
 
     var addGuest = function(event) {
-- 
1.7.10.4




More information about the Kimchi-devel mailing list