Skip to content

Commit

Permalink
Add escape of the path for the tesseract command. Closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
voz committed Mar 29, 2014
1 parent a72f3d4 commit 5141365
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/extractors/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ var extractText = function( filePath, options, cb ) {
}
}

exec( "tesseract " + filePath + " " + fileTempOutPath + " quiet",
// escape the paths for the tesseract command
var escapedFilePath = filePath.replace(/\s/g, '\\ ');
var escapedFileTempOutPath = fileTempOutPath.replace(/\s/g, '\\ ');

exec( "tesseract " + escapedFilePath + " " + escapedFileTempOutPath + " quiet",
execOptions,
function ( error, stdout, stderr ) {
if ( error !== null ) {
Expand All @@ -40,7 +44,7 @@ var extractText = function( filePath, options, cb ) {
if ( exists ) {
fs.readFile(fileTempOutPath + ".txt", function( error, text ) {
if (error) {
error = new Error( "Error reading tesseract output at [[ " + filePath + " ]], error: " + error );
error = new Error( "Error reading tesseract output at [[ " + fileTempOutPath + " ]], error: " + error );
cb( error, null );
} else {
fs.unlink(fileTempOutPath + ".txt", function(error) {
Expand All @@ -54,7 +58,7 @@ var extractText = function( filePath, options, cb ) {
}
});
} else {
error = new Error( "Error reading tesseract output at [[ " + filePath + " ]], file does not exist" );
error = new Error( "Error reading tesseract output at [[ " + fileTempOutPath + " ]], file does not exist" );
cb( error, null );
}
});
Expand Down

0 comments on commit 5141365

Please sign in to comment.