bug 376328 normalize file urls used in moz-icon, r=mscott, sr=vlad, a=juanb
authordveditz@cruzio.com
Mon, 30 Apr 2007 16:25:10 -0700
changeset 943 586d3b48896832b47c7aa1022bed4d071e29ec7b
parent 942 7d4acb18325d9a9f0e3f243e718f269599879fa8
child 944 ea840f4667c4ac3d00b7b215762da0dbea3a3790
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmscott, vlad, juanb
bugs376328
milestone1.9a5pre
bug 376328 normalize file urls used in moz-icon, r=mscott, sr=vlad, a=juanb
modules/libpr0n/decoders/icon/nsIconURI.cpp
--- a/modules/libpr0n/decoders/icon/nsIconURI.cpp
+++ b/modules/libpr0n/decoders/icon/nsIconURI.cpp
@@ -184,22 +184,23 @@ nsMozIconURI::GetSpec(nsACString &aSpec)
 // an attribute name of 'size=', this will return 32
 // Assumption: attribute pairs in the string are separated by '&'.
 void extractAttributeValue(const char * searchString, const char * attributeName, nsCString& result)
 {
   //NS_ENSURE_ARG_POINTER(extractAttributeValue);
 
   result.Truncate();
 
-	if (searchString && attributeName)
+  if (searchString && attributeName)
   {
     // search the string for attributeName
     PRUint32 attributeNameSize = strlen(attributeName);
     const char * startOfAttribute = PL_strcasestr(searchString, attributeName);
-    if (startOfAttribute)
+    if (startOfAttribute &&
+       ( *(startOfAttribute-1) == '?' || *(startOfAttribute-1) == '&') )
     {
       startOfAttribute += attributeNameSize; // skip over the attributeName
       if (*startOfAttribute) // is there something after the attribute name
       {
         const char * endofAttribute = strchr(startOfAttribute, '&');
         if (endofAttribute)
           result.Assign(Substring(startOfAttribute, endofAttribute));
         else
@@ -294,18 +295,26 @@ nsMozIconURI::SetSpec(const nsACString &
       if (!strncmp("//", mDummyFilePath.get(), 2))// must not have a url here..
       {
         // in this case the string looks like //somefile.html or // somefile.extension. So throw away the "//" part
         // and remember the rest in mDummyFilePath
         mDummyFilePath.Cut(0, 2); // cut the first 2 bytes....
       }
       if (!strncmp("file://", mDummyFilePath.get(), 7))
       { 
-        // we have a file url.....so store it...
-        rv = ioService->NewURI(mDummyFilePath, nsnull, nsnull, getter_AddRefs(mFileIcon));
+        // we have a file url, let the IOService normalize it
+        nsCOMPtr<nsIURI> tmpURI;
+        rv = ioService->NewURI(mDummyFilePath, nsnull, nsnull, getter_AddRefs(tmpURI));
+        if (NS_SUCCEEDED(rv) && tmpURI)
+        {
+          nsCAutoString filespec;
+          tmpURI->GetSpec(filespec);
+          if (filespec.Length() > 8 && filespec.CharAt(8) != '/')
+            mFileIcon = tmpURI; // looks good, save the file (bug 376328)
+        }
       }
       if (!sizeString.IsEmpty())
       {
         PRInt32 sizeValue = atoi(sizeString.get());
         // if the size value we got back is > 0 then use it
         if (sizeValue)
           mSize = sizeValue;
       }
@@ -511,18 +520,18 @@ nsMozIconURI::GetIconFile(nsIURI* * aFil
   *aFileUrl = mFileIcon;
   NS_IF_ADDREF(*aFileUrl);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMozIconURI::SetIconFile(nsIURI* aFileUrl)
 {
-  mFileIcon = aFileUrl;
-  return NS_OK;
+  // this isn't called anywhere, needs to go through SetSpec parsing
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsMozIconURI::GetImageSize(PRUint32 * aImageSize)  // measured by # of pixels in a row. defaults to 16.
 {
   *aImageSize = mSize;
   return NS_OK;
 }