From 5d6404d780883f404dcfaa7209ab926b0af32c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Mon, 19 Aug 2024 14:46:45 +0300 Subject: [PATCH] xml_add_ns: try a different namespace prefix, if the current one is in use The problem is with XML requests, which utilize in a child node a namespace with a prefix, which prefix was already added in the XML response to the root node. --- cassandane/tiny-tests/Caldav/calendar_setcolor | 12 ++++++------ imap/http_dav.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cassandane/tiny-tests/Caldav/calendar_setcolor b/cassandane/tiny-tests/Caldav/calendar_setcolor index 65dda07508..fa3ec2eecc 100644 --- a/cassandane/tiny-tests/Caldav/calendar_setcolor +++ b/cassandane/tiny-tests/Caldav/calendar_setcolor @@ -24,11 +24,11 @@ EOF my $propfindXml = < - - - - - + + + + + EOF # Assert that color isn't set. @@ -42,7 +42,7 @@ EOF $response = $CalDAV->Request('PROPPATCH', "/dav/calendars/user/cassandane/". $CalendarId, $proppatchXml, 'Content-Type' => 'text/xml'); - # Assert color ist set. + # Assert color is set. $response = $CalDAV->Request('PROPFIND', "/dav/calendars/user/cassandane/". $CalendarId, $propfindXml, 'Content-Type' => 'text/xml'); $propstat = $response->{'{DAV:}response'}[0]{'{DAV:}propstat'}[0]; diff --git a/imap/http_dav.c b/imap/http_dav.c index 9e7625e99b..fa89a35ec9 100644 --- a/imap/http_dav.c +++ b/imap/http_dav.c @@ -1340,8 +1340,14 @@ static int xml_add_ns(xmlNodePtr req, xmlNsPtr *respNs, xmlNodePtr root) ensure_ns(respNs, NS_JMAPCAL, root, (const char *) nsDef->href, (const char *) nsDef->prefix); - else - xmlNewNs(root, nsDef->href, nsDef->prefix); + else if (!xmlNewNs(root, nsDef->href, nsDef->prefix)) { + /* namespace prefix already in use */ + char myprefix[20]; + snprintf(myprefix, sizeof(myprefix), "X%X", strhash((const char *) nsDef->href) & 0xffff); + xmlFree((char *) nsDef->prefix); + nsDef->prefix = xmlStrdup(BAD_CAST myprefix); + xmlNewNs(root, nsDef->href, BAD_CAST myprefix); // could again return NULL + } } }