libidav/utils.c

changeset 59
6bd37fe6d905
parent 49
2f71f4ee247a
--- a/libidav/utils.c	Wed Oct 23 18:25:43 2024 +0200
+++ b/libidav/utils.c	Wed Oct 23 21:46:43 2024 +0200
@@ -731,6 +731,11 @@
 }
 
 char* util_path_to_url(DavSession *sn, const char *path) {
+    size_t pathlen = path ? strlen(path) : 0;
+    if(pathlen == 0) {
+        return strdup(sn->base_url);
+    }
+    
     CxBuffer url;
     cxBufferInit(&url, NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     
@@ -739,7 +744,7 @@
     // remove trailing slash
     cxBufferSeek(&url, -1, SEEK_CUR);
     
-    cxstring p = cx_str(path);
+    cxstring p = cx_strn(path, pathlen);
     
     CxStrtokCtx tkctx = cx_strtok(p, CX_STR("/"), INT_MAX);
     cxstring node;

mercurial