<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17952">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">manager.c: Generate valid XML if attribute names have leading digits.<br><br>The XML Manager Event Interface (amxml) now generates attribute names<br>that are compliant with the XML 1.1 specification. Previously, an<br>attribute name that started with a digit would be rendered as-is, even<br>though attribute names must not begin with a digit. We now prefix<br>attribute names that start with a digit with an underscore ('_') to<br>prevent XML validation failures.<br><br>This is not backwards compatible but my assumption is that compliant<br>XML parsers would already have been complaining about this.<br><br>ASTERISK-29886 #close<br><br>Change-Id: Icfaa56a131a082d803e9b7db5093806d455a0523<br>---<br>A doc/UPGRADE-staging/manager_amxml_attribute_fix.txt<br>M main/manager.c<br>2 files changed, 22 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/52/17952/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt b/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..4b15ee9</span><br><span>--- /dev/null</span><br><span>+++ b/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt</span><br><span>@@ -0,0 +1,8 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: AMI</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The XML Manager Event Interface (amxml) now generates attribute names</span><br><span style="color: hsl(120, 100%, 40%);">+that are compliant with the XML 1.1 specification. Previously, an</span><br><span style="color: hsl(120, 100%, 40%);">+attribute name that started with a digit would be rendered as-is, even</span><br><span style="color: hsl(120, 100%, 40%);">+though attribute names must not begin with a digit. We now prefix</span><br><span style="color: hsl(120, 100%, 40%);">+attribute names that start with a digit with an underscore ('_') to</span><br><span style="color: hsl(120, 100%, 40%);">+prevent XML validation failures.</span><br><span>diff --git a/main/manager.c b/main/manager.c</span><br><span>index 8307421..129ef38 100644</span><br><span>--- a/main/manager.c</span><br><span>+++ b/main/manager.c</span><br><span>@@ -7639,6 +7639,7 @@</span><br><span>  /* store in a local buffer to avoid calling ast_str_append too often */</span><br><span>      char buf[256];</span><br><span>       char *dst = buf;</span><br><span style="color: hsl(120, 100%, 40%);">+      const char *save = src;</span><br><span>      int space = sizeof(buf);</span><br><span>     /* repeat until done and nothing to flush */</span><br><span>         for ( ; *src || dst != buf ; src++) {</span><br><span>@@ -7652,10 +7653,19 @@</span><br><span>                      }</span><br><span>            }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-           if ( (mode & 2) && !isalnum(*src)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        *dst++ = '_';</span><br><span style="color: hsl(0, 100%, 40%);">-                   space--;</span><br><span style="color: hsl(0, 100%, 40%);">-                        continue;</span><br><span style="color: hsl(120, 100%, 40%);">+             if (mode & 2) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   if (save == src && isdigit(*src)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                           /* The first character of an XML attribute cannot be a digit */</span><br><span style="color: hsl(120, 100%, 40%);">+                               *dst++ = '_';</span><br><span style="color: hsl(120, 100%, 40%);">+                         *dst++ = *src;</span><br><span style="color: hsl(120, 100%, 40%);">+                                space -= 2;</span><br><span style="color: hsl(120, 100%, 40%);">+                           continue;</span><br><span style="color: hsl(120, 100%, 40%);">+                     } else if (!isalnum(*src)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                          /* Replace non-alphanumeric with an underscore */</span><br><span style="color: hsl(120, 100%, 40%);">+                             *dst++ = '_';</span><br><span style="color: hsl(120, 100%, 40%);">+                         space--;</span><br><span style="color: hsl(120, 100%, 40%);">+                              continue;</span><br><span style="color: hsl(120, 100%, 40%);">+                     }</span><br><span>            }</span><br><span>            switch (*src) {</span><br><span>              case '<':</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17952">change 17952</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17952"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: Icfaa56a131a082d803e9b7db5093806d455a0523 </div>
<div style="display:none"> Gerrit-Change-Number: 17952 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>