1487c9a724e9516494ffe7b9bb407c5c17bdde27
galt
  Wed Oct 17 17:44:41 2012 -0700
fix for #9390 - tolerating url-encoded urls when detecting file compression type
diff --git src/lib/linefile.c src/lib/linefile.c
index f092331..48dd049 100644
--- src/lib/linefile.c
+++ src/lib/linefile.c
@@ -1,66 +1,76 @@
 /* lineFile - stuff to rapidly read text files and parse them into
  * lines.
  *
  * This file is copyright 2002 Jim Kent, but license is hereby
  * granted for all use - public, private or commercial. */
 
 #include "common.h"
 #include "hash.h"
 #include <fcntl.h>
 #include <signal.h>
 #include "dystring.h"
 #include "errabort.h"
 #include "linefile.h"
 #include "pipeline.h"
 #include "localmem.h"
+#include "cheapcgi.h"
 
 char *getFileNameFromHdrSig(char *m)
 /* Check if header has signature of supported compression stream,
    and return a phoney filename for it, or NULL if no sig found. */
 {
 char buf[20];
 char *ext=NULL;
 if (startsWith("\x1f\x8b",m)) ext = "gz";
 else if (startsWith("\x1f\x9d\x90",m)) ext = "Z";
 else if (startsWith("BZ",m)) ext = "bz2";
 else if (startsWith("PK\x03\x04",m)) ext = "zip";
 if (ext==NULL)
     return NULL;
 safef(buf, sizeof(buf), "somefile.%s", ext);
 return cloneString(buf);
 }
 
 static char **getDecompressor(char *fileName)
 /* if a file is compressed, return the command to decompress the
  * approriate format, otherwise return NULL */
 {
 static char *GZ_READ[] = {"gzip", "-dc", NULL};
 static char *Z_READ[] = {"gzip", "-dc", NULL};
 static char *BZ2_READ[] = {"bzip2", "-dc", NULL};
 static char *ZIP_READ[] = {"gzip", "-dc", NULL};
 
-if (endsWith(fileName, ".gz"))
-    return GZ_READ;
-else if (endsWith(fileName, ".Z"))
-    return Z_READ;
-else if (endsWith(fileName, ".bz2"))
-    return BZ2_READ;
-else if (endsWith(fileName, ".zip"))
-    return ZIP_READ;
-else
-    return NULL;
+char **result = NULL;
+char *fileNameDecoded = cloneString(fileName);
+if (startsWith("http://" , fileName)
+ || startsWith("https://", fileName)
+ || startsWith("ftp://",   fileName))
+    cgiDecode(fileName, fileNameDecoded, strlen(fileName));
+
+if      (endsWith(fileNameDecoded, ".gz"))
+    result = GZ_READ;
+else if (endsWith(fileNameDecoded, ".Z"))
+    result = Z_READ;
+else if (endsWith(fileNameDecoded, ".bz2"))
+    result = BZ2_READ;
+else if (endsWith(fileNameDecoded, ".zip"))
+    result = ZIP_READ;
+
+freeMem(fileNameDecoded);
+return result;
+
 }
 
 static void metaDataAdd(struct lineFile *lf, char *line)
 /* write a line of metaData to output file
  * internal function called by lineFileNext */
 {
 struct metaOutput *meta = NULL;
 
 if (lf->isMetaUnique)
     {
     /* suppress repetition of comments */
     if (hashLookup(lf->metaLines, line))
         {
         return;
         }