]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
manager.c: Generate valid XML if attribute names have leading digits.
authorSean Bright <sean.bright@gmail.com>
Mon, 31 Jan 2022 18:52:26 +0000 (13:52 -0500)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Thu, 3 Feb 2022 13:55:31 +0000 (07:55 -0600)
The XML Manager Event Interface (amxml) now generates attribute names
that are compliant with the XML 1.1 specification. Previously, an
attribute name that started with a digit would be rendered as-is, even
though attribute names must not begin with a digit. We now prefix
attribute names that start with a digit with an underscore ('_') to
prevent XML validation failures.

This is not backwards compatible but my assumption is that compliant
XML parsers would already have been complaining about this.

ASTERISK-29886 #close

Change-Id: Icfaa56a131a082d803e9b7db5093806d455a0523

doc/UPGRADE-staging/manager_amxml_attribute_fix.txt [new file with mode: 0644]
main/manager.c

diff --git a/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt b/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt
new file mode 100644 (file)
index 0000000..4b15ee9
--- /dev/null
@@ -0,0 +1,8 @@
+Subject: AMI
+
+The XML Manager Event Interface (amxml) now generates attribute names
+that are compliant with the XML 1.1 specification. Previously, an
+attribute name that started with a digit would be rendered as-is, even
+though attribute names must not begin with a digit. We now prefix
+attribute names that start with a digit with an underscore ('_') to
+prevent XML validation failures.
index 23e5575102d778e49560cb3738973eb87f1fb4b4..1a1016f4b88bf30b1a997c371d296d0d59a5a073 100644 (file)
@@ -7644,6 +7644,7 @@ static void xml_copy_escape(struct ast_str **out, const char *src, int mode)
        /* store in a local buffer to avoid calling ast_str_append too often */
        char buf[256];
        char *dst = buf;
+       const char *save = src;
        int space = sizeof(buf);
        /* repeat until done and nothing to flush */
        for ( ; *src || dst != buf ; src++) {
@@ -7657,10 +7658,19 @@ static void xml_copy_escape(struct ast_str **out, const char *src, int mode)
                        }
                }
 
-               if ( (mode & 2) && !isalnum(*src)) {
-                       *dst++ = '_';
-                       space--;
-                       continue;
+               if (mode & 2) {
+                       if (save == src && isdigit(*src)) {
+                               /* The first character of an XML attribute cannot be a digit */
+                               *dst++ = '_';
+                               *dst++ = *src;
+                               space -= 2;
+                               continue;
+                       } else if (!isalnum(*src)) {
+                               /* Replace non-alphanumeric with an underscore */
+                               *dst++ = '_';
+                               space--;
+                               continue;
+                       }
                }
                switch (*src) {
                case '<':