[Asterisk-code-review] manager.c: Generate valid XML if attribute names have leading digits. (asterisk[18])
Friendly Automation
asteriskteam at digium.com
Thu Feb 3 07:54:48 CST 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/17952 )
Change subject: manager.c: Generate valid XML if attribute names have leading digits.
......................................................................
manager.c: Generate valid XML if attribute names have leading digits.
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
---
A doc/UPGRADE-staging/manager_amxml_attribute_fix.txt
M main/manager.c
2 files changed, 22 insertions(+), 4 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt b/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt
new file mode 100644
index 0000000..4b15ee9
--- /dev/null
+++ b/doc/UPGRADE-staging/manager_amxml_attribute_fix.txt
@@ -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.
diff --git a/main/manager.c b/main/manager.c
index 8307421..129ef38 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -7639,6 +7639,7 @@
/* 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++) {
@@ -7652,10 +7653,19 @@
}
}
- 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 '<':
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17952
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Icfaa56a131a082d803e9b7db5093806d455a0523
Gerrit-Change-Number: 17952
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220203/f8b1cb71/attachment-0001.html>
More information about the asterisk-code-review
mailing list