Skip to content
This repository

Fixed bug with incorrect handling files with whitespaces in its names #7

Open
wants to merge 1 commit into from

3 participants

Mikhail Emelchenkov Christos Trochalakis Roman Arutyunyan
Mikhail Emelchenkov

Fixed bug with incorrect handling files with whitespaces in its names.
Some WebDAV clients, i.e. Cyberduck, just ignored files with whitespaces in its names until this fix.

Mikhail Emelchenkov Fixed bug with incorrect handling files with whitespaces in its names
Some WebDAV clients, i.e. Cyberduck, just ignored files with whitespaces in its names until this fix.
71d0e4f
Christos Trochalakis

Hello @arut,

I am one of debian's nginx maintainers. We include dav-ext in our nginx-full and nginx-extras flavours.

A few days back we received a bug report to include mikhail's patch to our builds but we are not happy, nor confident to add 3rd party patches for no reason. Could you provide some feedback about this issue/patch? If you could merge it in your tree and release a 0.0.3 version will be even better.

Thank you,
chris

Roman Arutyunyan
Owner
arut commented March 16, 2014

Unfortunately the patch is big and mostly changes code style rather than fixes something. I'll analyze the problem when I have time.

Christos Trochalakis

That would be great. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 05, 2012
Mikhail Emelchenkov Fixed bug with incorrect handling files with whitespaces in its names
Some WebDAV clients, i.e. Cyberduck, just ignored files with whitespaces in its names until this fix.
71d0e4f
This page is out of date. Refresh to see the latest.
16  README
@@ -4,6 +4,9 @@ NGINX WebDAV missing commands support (PROPFIND & OPTIONS)
4 4
 
5 5
 (c) 2012 Arutyunyan Roman (arut@qip.ru)
6 6
 
  7
+Contributors:
  8
+Mikhail Emelchenkov @ MyLove Company, LLC (mikhail@mylovecompany.com)
  9
+
7 10
 
8 11
 For full WebDAV support in NGINX you need to turn on standard NGINX 
9 12
 WebDAV module (providing partial WebDAV implementation) as well as 
@@ -27,3 +30,16 @@ Example config:
27 30
 
28 31
 		root /var/root/;
29 32
 	}
  33
+
  34
+
  35
+Important note:
  36
+
  37
+People often use WebDAV with digest authentication, and there is a
  38
+Nginx third party module nginx-http-auth-digest.
  39
+
  40
+Don't use original version from
  41
+https://github.com/samizdatco/nginx-http-auth-digest/, it has a bug
  42
+which prevents uploading files with whitespaces in their names.
  43
+
  44
+Use well-maintained fork from
  45
+https://github.com/chazmcgarvey/nginx-http-auth-digest instead.
119  ngx_http_dav_ext_module.c
... ...
@@ -1,6 +1,9 @@
1 1
 /******************************************************************************
2 2
   Copyright (c) 2012, Roman Arutyunyan (arut@qip.ru)
3 3
   All rights reserved.
  4
+  
  5
+  Contributors:
  6
+  Mikhail Emelchenkov @ MyLove Company, LLC (mikhail@mylovecompany.com)
4 7
 
5 8
   Redistribution and use in source and binary forms, with or without modification, 
6 9
   are permitted provided that the following conditions are met:
@@ -209,49 +212,99 @@ static void ngx_http_dav_ext_end_xml_elt(void *user_data, const XML_Char *name)
209 212
 #define NGX_HTTP_DAV_EXT_COPY    0x01
210 213
 #define NGX_HTTP_DAV_EXT_ESCAPE  0x02
211 214
 
212  
-static void
213  
-ngx_http_dav_ext_output(ngx_http_request_t *r, ngx_chain_t **ll,
214  
-	ngx_int_t flags, u_char *data, ngx_uint_t len) 
  215
+uintptr_t
  216
+ngx_http_dav_ext_escape_html(u_char *dst, u_char *src, size_t size)
215 217
 {
216  
-	ngx_chain_t *cl;
217  
-	ngx_buf_t   *b;
  218
+    u_char      ch;
  219
+    ngx_uint_t  len;
218 220
 
219  
-	if (!len) {
220  
-		return; 
221  
-	}
  221
+    if (dst == NULL) {
222 222
 
223  
-	if (flags & NGX_HTTP_DAV_EXT_ESCAPE) {
  223
+        len = 0;
224 224
 
225  
-		b = ngx_create_temp_buf(r->pool, len + ngx_escape_html(NULL, data, len));
226  
-		b->last = (u_char*)ngx_escape_html(b->pos, data, len);
  225
+        while (size) {
  226
+            switch (*src++) {
227 227
 
228  
-	} else if (flags & NGX_HTTP_DAV_EXT_COPY) {
  228
+            case ' ':
  229
+                len += sizeof("%20") - 2;
  230
+                break;
229 231
 
230  
-		b = ngx_create_temp_buf(r->pool, len);
231  
-		b->last = ngx_cpymem(b->pos, data, len);
  232
+            default:
  233
+                break;
  234
+            }
  235
+            size--;
  236
+        }
232 237
 
233  
-	} else {
  238
+        return (uintptr_t) len;
  239
+    }
234 240
 
235  
-		b = ngx_calloc_buf(r->pool);
236  
-		b->memory = 1;
237  
-		b->pos = data;
238  
-		b->start = data;
239  
-		b->last = b->pos + len;
240  
-		b->end = b->last;
241  
-	}
  241
+    while (size) {
  242
+        ch = *src++;
242 243
 
243  
-	cl = ngx_alloc_chain_link(r->pool);
244  
-	cl->buf = b;
245  
-	cl->next = NULL;
  244
+        switch (ch) {
246 245
 
247  
-	if (*ll != NULL) {
248  
-		cl->next = (*ll)->next;
249  
-		(*ll)->next = cl;
250  
-		*ll = cl;
251  
-	} else {
252  
-		*ll = cl;
253  
-		cl->next = cl;
254  
-	}
  246
+        case ' ':
  247
+            *dst++ = '%'; *dst++ = '2'; *dst++ = '0'; 
  248
+            break;
  249
+
  250
+        default:
  251
+            *dst++ = ch;
  252
+            break;
  253
+        }
  254
+        size--;
  255
+    }
  256
+
  257
+    return (uintptr_t) dst;
  258
+}
  259
+
  260
+static void
  261
+ngx_http_dav_ext_output(ngx_http_request_t *r, ngx_chain_t **ll,
  262
+    ngx_int_t flags, u_char *data, ngx_uint_t len) 
  263
+{
  264
+    ngx_chain_t *cl;
  265
+    ngx_uint_t  len_int;
  266
+    ngx_buf_t   *b, *b_int /* internal buffer */;
  267
+
  268
+    if (!len) {
  269
+        return; 
  270
+    }
  271
+
  272
+    if (flags & NGX_HTTP_DAV_EXT_ESCAPE) {
  273
+        len_int = len + ngx_escape_html(NULL, data, len);
  274
+        b_int = ngx_create_temp_buf(r->pool, len_int);
  275
+        b_int->last = (u_char*)ngx_escape_html(b_int->pos, data, len);
  276
+        
  277
+        len = len_int + ngx_http_dav_ext_escape_html(NULL, b_int->pos, len_int);
  278
+        b = ngx_create_temp_buf(r->pool, len);
  279
+        b->last = (u_char*)ngx_http_dav_ext_escape_html(b->pos, b_int->pos, len_int);
  280
+        
  281
+        ngx_pfree(r->pool, b_int);
  282
+        
  283
+    } else if (flags & NGX_HTTP_DAV_EXT_COPY) {
  284
+        b = ngx_create_temp_buf(r->pool, len);
  285
+        b->last = ngx_cpymem(b->pos, data, len);
  286
+
  287
+    } else {
  288
+        b = ngx_calloc_buf(r->pool);
  289
+        b->memory = 1;
  290
+        b->pos = data;
  291
+        b->start = data;
  292
+        b->last = b->pos + len;
  293
+        b->end = b->last;
  294
+    }
  295
+
  296
+    cl = ngx_alloc_chain_link(r->pool);
  297
+    cl->buf = b;
  298
+    cl->next = NULL;
  299
+
  300
+    if (*ll != NULL) {
  301
+        cl->next = (*ll)->next;
  302
+        (*ll)->next = cl;
  303
+        *ll = cl;
  304
+    } else {
  305
+        *ll = cl;
  306
+        cl->next = cl;
  307
+    }
255 308
 }
256 309
 
257 310
 static void
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.