? SOLR-1274.patch
? TIKA-324.patch
? Untitled-2
? cleanup-490078.patch
? docs-540974-10.patch
? dump.tcp
? escape-506526-6.patch
? escape-506526-7.patch
? force-utf8-622508-7.patch
? force-utf8-622508-8.patch
? get-to-index-changes-461514-1.patch
? icons
? kkk{ass
? nopath-610816-1.patch
? test.txt
? text-format-616426-1.patch
? tika-attachments-449214-3.patch
? xxx"lll
? xxx&lll
Index: apachesolr_attachments.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr_attachments/apachesolr_attachments.module,v
retrieving revision 1.16
diff -u -p -r1.16 apachesolr_attachments.module
--- apachesolr_attachments.module	18 Nov 2009 03:51:00 -0000	1.16
+++ apachesolr_attachments.module	19 Nov 2009 04:25:51 -0000
@@ -402,10 +402,16 @@ function _asa_get_cck_file_fields() {
 
 /**
  * Parse the attachment getting just the raw text.
+ *
+ * @throws Exception
  */
 function _asa_get_attachment_text($file) {
   // Any down-side to using realpath()?
   $filepath = realpath($file->filepath);
+  // Check that we have a valid filepath.
+  if (!($filepath) || !is_file($filepath)) {
+    return FALSE;
+  }
 
   // No need to use java for plain text files.
   if ($file->filemime == 'text/plain' || $file->filemime == 'text/x-diff') {
@@ -449,18 +455,23 @@ function _asa_get_attachment_text($file)
 
 /**
  * For a file path, try to extract text using a local tika jar.
+ *
+ * @throws Exception
  */
 function apachesolr_attachments_extract_using_tika($filepath) {
   $tika_path = realpath(variable_get('apachesolr_attachments_tika_path', ''));
-
-  $tika = $tika_path .'/'. variable_get('apachesolr_attachments_tika_jar', 'tika-0.3.jar');
-
+  $tika = realpath($tika_path .'/'. variable_get('apachesolr_attachments_tika_jar', 'tika-0.3.jar'));
+  if (!($tika) || !is_file($tika)) {
+    throw new Exception(t('Invalid path or filename for tika application jar.'));
+  }
   $java = variable_get('apachesolr_attachments_java', 'java');
   // By default force UTF-8 output.
   $java_opts = ' ' . variable_get('apachesolr_attachments_java_opts', '-Dfile.encoding=UTF8');
-  $cmd = escapeshellcmd($java . $java_opts .' -cp '. $tika_path .' -jar '. $tika .' -t "'. $filepath .'"');
+  // Escape quote marks in the file name.
+  $filepath = str_replace('"', '\\"', $filepath);
+  $cmd = escapeshellcmd($java . $java_opts) .' -cp "'. $tika_path .'" -jar "'. $tika .'" -t "'. $filepath .'"';
 
-  // Add a work-around for a MAMP bug.
+  // Add a work-around for a MAMP bug + java 1.5.
   if (strpos(ini_get('extension_dir'), 'MAMP/')) {
     $cmd = 'export DYLD_LIBRARY_PATH=""; '. $cmd;
   }
