Skip to main content.
home | support | download

Back to List Archive

Patch for the quotes in filenames bug

From: Ludovic Drolez <ldrolez(at)not-real.debian.org>
Date: Tue Sep 19 2006 - 20:45:03 GMT
This is a multi-part message in MIME format.
--------------050505030107040602070000
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi !

I currently maintain Swish-e for Debian, and since Etch and Swish-e 2.4.4
will be released soon (!?), I wanted to fix a bug which prevents me from
indexing .doc dans .pdf files with quotes in their file name...

I had to modify filter.c but that was not very hard, as you can see in the
attached patch. I escape all non-alphanumeric characters so the shell is
happy when launching any filter specified by 'FileFilter'.

You can now simply use the filefilter directives without quotes, and any
filename should be ok:
Filefilter  .pdf   swish_filter.pl %p
Filefilter  .doc   swish_filter.pl %p

Cheers,

  Ludovic.

PS: Ooops ! I've forgotten a 'free' in 'stringQuote()'.

-- 
Ludovic Drolez.

http://zaurus.palmopensource.com    - The Zaurus Open Source Portal
http://www.drolez.com      - Personal site - Linux and PalmOS stuff


--------------050505030107040602070000
Content-Type: text/plain;
 name="filter.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="filter.c.diff"

--- filter.c	2003-03-28 17:31:33.000000000 +0100
+++ filter.c.mod	2006-09-19 19:20:00.000000000 +0200
@@ -323,7 +323,7 @@
 
     /* if no filter cmd param given, use default */
 
-    opt_mask = (fi->options && *(fi->options) ) ? fi->options : "'%p' '%P'";
+    opt_mask = (fi->options && *(fi->options) ) ? fi->options : "%p %P";
     cmd_opts = filterCallCmdOptStr(opt_mask, fprop);
 
     len = strlen(fi->prog) + strlen(cmd_opts);
@@ -373,7 +373,7 @@
     char   *cmdopt,
            *co,
            *om;
-    int     max = MAXSTRLEN *3;
+    int     max = MAXSTRLEN *4;
 
 
     cmdopt = (char *) emalloc(max);
@@ -384,7 +384,7 @@
     while (*om) {
 
         /* Argh! no overflow checking. Fix $$$ - Mar 2002 - moseley */
-
+	
         switch (*om) {
 
         case '\\':
@@ -420,10 +420,12 @@
 
     case 'P':                  /* Full Doc Path/URL */
         strcpy(str, (fprop->real_path) ? fprop->real_path : nul);
+	stringQuote(str);
         break;
 
     case 'p':                  /* Full Path TMP/Work path */
         strcpy(str, (fprop->work_path) ? fprop->work_path : nul);
+	stringQuote(str);
 #ifdef _WIN32
         make_windows_path( str );
 #endif
@@ -469,4 +471,22 @@
     return str;
 }
 
+/*
+ * Fix for Debian: escape all non alphanum characters in paths
+ * --  Ludovic Drolez
+ */
+void stringQuote(char *str)
+{
+    char *copy;
+    
+    copy = (char *) emalloc(strlen(str)+1);
+    strcpy(copy, str);
 
+    for ( ;*copy; ) {
+	if (!isalnum(*copy) && (*copy != '/') ) {
+		*str++ = '\\';	
+	}
+	*str++ = *copy++;
+    }
+    *str = 0;
+}

--------------050505030107040602070000--
Received on Tue Sep 19 13:45:09 2006