Bug 788741 - Truncate file extension if too long r=bz
authorAndrew Quartey <andrew.quartey@gmail.com>
Tue, 18 Sep 2012 16:45:51 -0400
changeset 107531 e1850b0b8d4a61bf782c7a883527088f61be41c8
parent 107530 83925e07123566c5fa002d9d9551432e52ae2c5c
child 107532 a19948eb6c26ef83cc8a9c6b6023d94d17a48110
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersbz
bugs788741
milestone18.0a1
Bug 788741 - Truncate file extension if too long r=bz
embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
--- a/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
+++ b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
@@ -2208,17 +2208,23 @@ nsWebBrowserPersist::CalculateAndAppendF
                     mimeInfo->GetPrimaryExtension(fileExt);
                 } 
 
                 if (!fileExt.IsEmpty())
                 {
                     uint32_t newLength = newFileName.Length() + fileExt.Length() + 1;
                     if (newLength > kDefaultMaxFilenameLength)
                     {
-                        newFileName.Truncate(newFileName.Length() - (newLength - kDefaultMaxFilenameLength));
+                        if (fileExt.Length() > kDefaultMaxFilenameLength/2)
+                            fileExt.Truncate(kDefaultMaxFilenameLength/2);
+
+                        uint32_t diff = kDefaultMaxFilenameLength - 1 -
+                                        fileExt.Length();
+                        if (newFileName.Length() > diff)
+                            newFileName.Truncate(diff);
                     }
                     newFileName.Append(".");
                     newFileName.Append(fileExt);
                 }
 
                 if (localFile)
                 {
                     localFile->SetLeafName(NS_ConvertUTF8toUTF16(newFileName));