Replace '/' by '-' in filenames of attachments

Fixes #2537
pull/17/head
Francis Lachapelle 2014-02-07 14:00:36 -05:00
parent eee5beb698
commit 7118bbe0ab
3 changed files with 13 additions and 4 deletions

1
NEWS
View File

@ -43,6 +43,7 @@ Bug fixes
- encode HTML entities in JSON data returned by Calendar module (#2598)
- fixed handling of ACLs on shared calendars with multiple groups (#1854)
- fixed HTML formatting of appointment notifications for Outlook (#2233)
- replace slashes by dashes in filenames of attachments to avoid a 404 return code (#2537)
2.1.1b (2013-12-04)
-------------------

View File

@ -761,7 +761,7 @@ static BOOL debugSoParts = NO;
withPath: (NSString *) path
andPrefix: (NSString *) prefix
{
NSString *filename, *mimeType;
NSString *filename, *mimeType, *filenameURL;
NSDictionary *currentFile;
filename = [part filename];
@ -783,14 +783,18 @@ static BOOL debugSoParts = NO;
if (filename)
{
// We replace any slash by a dash since Apache won't allow encoded slashes by default.
// See http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes
// See [UIxMailPartViewer _filenameForAttachment:]
filenameURL = [[filename stringByReplacingString: @"/" withString: @"-"] stringByEscapingURL];
currentFile = [NSDictionary dictionaryWithObjectsAndKeys:
filename, @"filename",
[mimeType lowercaseString], @"mimetype",
path, @"path",
[part objectForKey: @"encoding"], @"encoding",
[part objectForKey:@ "size"], @"size",
[NSString stringWithFormat: @"%@/%@", prefix, [filename stringByEscapingURL]], @"url",
[NSString stringWithFormat: @"%@/asAttachment/%@", prefix, [filename stringByEscapingURL]], @"urlAsAttachment",
[NSString stringWithFormat: @"%@/%@", prefix, filenameURL], @"url",
[NSString stringWithFormat: @"%@/asAttachment/%@", prefix, filenameURL], @"urlAsAttachment",
nil];
[keys addObject: currentFile];
}

View File

@ -267,7 +267,11 @@
NSString *extension;
filename = [NSMutableString stringWithString: [self filename]];
if (![filename length])
if ([filename length])
// We replace any slash by a dash since Apache won't allow encoded slashes by default.
// See http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes
filename = [filename stringByReplacingString: @"/" withString: @"-"];
else
[filename appendFormat: @"%@-%@",
[self labelForKey: @"Untitled"],
[bodyPart nameInContainer]];