]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
xml: omit domain name from comment if it contains double hyphen
authorJán Tomko <jtomko@redhat.com>
Tue, 23 Oct 2012 12:16:44 +0000 (14:16 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 23 Oct 2012 12:24:31 +0000 (14:24 +0200)
We put a comment containing "virsh edit <domain_name>" at the start of
the XML. W3C recommendation forbids the use of "--" in comments [1] and
libvirt can't parse it either. This patch omits the domain name if it
contains a double hyphen.

[1] http://www.w3.org/TR/REC-xml/#sec-comments

src/util/xml.c

index 39bc1114f264a96317970696f6545b126d98e025..f3dc2563358f00d12826db3260d745d7ec911daf 100644 (file)
@@ -807,12 +807,16 @@ or other application using the libvirt API.\n\
     if (safewrite(fd, cmd, len) != len)
         return -1;
 
-    if (safewrite(fd, " ", 1) != 1)
-        return -1;
+    /* Omit the domain name if it contains a double hyphen
+     * because they aren't allowed in XML comments */
+    if (!strstr(name, "--")) {
+        if (safewrite(fd, " ", 1) != 1)
+            return -1;
 
-    len = strlen(name);
-    if (safewrite(fd, name, len) != len)
-        return -1;
+        len = strlen(name);
+        if (safewrite(fd, name, len) != len)
+            return -1;
+    }
 
     len = strlen(epilogue);
     if (safewrite(fd, epilogue, len) != len)