src/server/util/uri.c

changeset 695
ff14b97bdf14
parent 386
b91f8efadb63
child 696
27e42da5050f
--- a/src/server/util/uri.c	Sat Feb 21 21:52:08 2026 +0100
+++ b/src/server/util/uri.c	Sun Feb 22 09:24:41 2026 +0100
@@ -267,6 +267,37 @@
     return od;
 }
 
+NSAPI_PUBLIC size_t util_uri_escape_s(char *buf, size_t len, const char *s) {
+    char *d = buf;
+    ssize_t dlen = len;
+    if(dlen <= 0) {
+        return 0;
+    }
+    
+    while (*s) {
+        if (strchr("% ?#:+&*\"'<>\r\n", *s)) {
+            snprintf(d, dlen, "%%%02x", (unsigned char)*s);
+            ++s;
+            d += 3;
+            dlen -= 3;
+        } else if (0x80 & *s) {
+            snprintf(d, dlen, "%%%02x", (unsigned char)*s);
+            ++s;
+            d += 3;
+            dlen -= 3;
+        } else {
+            *d++ = *s++;
+            dlen--;
+        }
+        
+        if(dlen <= 0) {
+            return 0;
+        }
+    }
+    *d = '\0';
+    return d - buf;
+}
+
 
 /* --------------------------- util_url_escape ---------------------------- */
 

mercurial