Skip to content

Commit

Permalink
Revert " MDL-45044 filter_tex: properly escape excutable pathnames fo…
Browse files Browse the repository at this point in the history
…r Windows"

This reverts commit f0da509.
  • Loading branch information
stronk7 committed Jun 26, 2014
1 parent d70fe4f commit 078379a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
5 changes: 2 additions & 3 deletions filter/tex/latex.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function render( $formula, $filename, $fontsize=12, $density=240, $background=''
if (empty($pathlatex)) {
return false;
}
$pathlatex = escapeshellarg(trim($pathlatex, " '\""));

$doc = $this->construct_latex_document( $formula, $fontsize );

Expand All @@ -118,7 +117,7 @@ function render( $formula, $filename, $fontsize=12, $density=240, $background=''
}

// run dvips (.dvi to .ps)
$pathdvips = escapeshellarg(trim(get_config('filter_tex', 'pathdvips'), " '\""));
$pathdvips = get_config('filter_tex', 'pathdvips');
$command = "{$pathdvips} -E $dvi -o $ps";
if ($this->execute($command, $log )) {
return false;
Expand All @@ -130,7 +129,7 @@ function render( $formula, $filename, $fontsize=12, $density=240, $background=''
} else {
$bg_opt = "";
}
$pathconvert = escapeshellarg(trim(get_config('filter_tex', 'pathconvert'), " '\""));
$pathconvert = get_config('filter_tex', 'pathconvert');
$command = "{$pathconvert} -density $density -trim $bg_opt $ps $img";
if ($this->execute($command, $log )) {
return false;
Expand Down
5 changes: 2 additions & 3 deletions filter/tex/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ function filter_tex_updatedcallback($name) {
return;
}

$pathlatex = trim($pathlatex, " '\"");
$pathdvips = trim(get_config('filter_tex', 'pathdvips'), " '\"");
$pathconvert = trim(get_config('filter_tex', 'pathconvert'), " '\"");
$pathdvips = get_config('filter_tex', 'pathdvips');
$pathconvert = get_config('filter_tex', 'pathconvert');

if (!(is_file($pathlatex) && is_executable($pathlatex) &&
is_file($pathdvips) && is_executable($pathdvips) &&
Expand Down
16 changes: 3 additions & 13 deletions filter/tex/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,16 @@
} else if (PHP_OS=='WINNT' or PHP_OS=='WIN32' or PHP_OS=='Windows') {
// note: you need Ghostscript installed (standard), miktex (standard)
// and ImageMagick (install at c:\ImageMagick)
$default_filter_tex_pathlatex = "c:\\texmf\\miktex\\bin\\latex.exe";
$default_filter_tex_pathdvips = "c:\\texmf\\miktex\\bin\\dvips.exe";
$default_filter_tex_pathconvert = "c:\\imagemagick\\convert.exe";
$default_filter_tex_pathlatex = "\"c:\\texmf\\miktex\\bin\\latex.exe\" ";
$default_filter_tex_pathdvips = "\"c:\\texmf\\miktex\\bin\\dvips.exe\" ";
$default_filter_tex_pathconvert = "\"c:\\imagemagick\\convert.exe\" ";

} else {
$default_filter_tex_pathlatex = '';
$default_filter_tex_pathdvips = '';
$default_filter_tex_pathconvert = '';
}

$pathlatex = get_config('filter_tex', 'pathlatex');
$pathdvips = get_config('filter_tex', 'pathdvips');
$pathconvert = get_config('filter_tex', 'pathconvert');
if (strrpos($pathlatex . $pathdvips . $pathconvert, '"') or
strrpos($pathlatex . $pathdvips . $pathconvert, "'")) {
set_config('pathlatex', trim($pathlatex, " '\""), 'filter_tex');
set_config('pathdvips', trim($pathdvips, " '\""), 'filter_tex');
set_config('pathconvert', trim($pathconvert, " '\""), 'filter_tex');
}

$items[] = new admin_setting_configexecutable('filter_tex/pathlatex', get_string('pathlatex', 'filter_tex'), '', $default_filter_tex_pathlatex);
$items[] = new admin_setting_configexecutable('filter_tex/pathdvips', get_string('pathdvips', 'filter_tex'), '', $default_filter_tex_pathdvips);
$items[] = new admin_setting_configexecutable('filter_tex/pathconvert', get_string('pathconvert', 'filter_tex'), '', $default_filter_tex_pathconvert);
Expand Down
9 changes: 3 additions & 6 deletions filter/tex/texdebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,23 @@ function TexOutput($expression, $graphic=false) {
// first check if it is likely to work at all
$output .= "<h3>Checking executables</h3>\n";
$executables_exist = true;
$pathlatex = trim(get_config('filter_tex', 'pathlatex'), " '\"");
$pathlatex = get_config('filter_tex', 'pathlatex');
if (is_file($pathlatex)) {
$output .= "latex executable ($pathlatex) is readable<br />\n";
}
else {
$executables_exist = false;
$output .= "<b>Error:</b> latex executable ($pathlatex) is not readable<br />\n";
}
$pathdvips = trim(get_config('filter_tex', 'pathdvips'), " '\"");
$pathdvips = get_config('filter_tex', 'pathdvips');
if (is_file($pathdvips)) {
$output .= "dvips executable ($pathdvips) is readable<br />\n";
}
else {
$executables_exist = false;
$output .= "<b>Error:</b> dvips executable ($pathdvips) is not readable<br />\n";
}
$pathconvert = trim(get_config('filter_tex', 'pathconvert'), " '\"");
$pathconvert = get_config('filter_tex', 'pathconvert');
if (is_file($pathconvert)) {
$output .= "convert executable ($pathconvert) is readable<br />\n";
}
Expand Down Expand Up @@ -248,17 +248,14 @@ function TexOutput($expression, $graphic=false) {
chdir($latex->temp_dir);

// step 1: latex command
$pathlatex = escapeshellarg($pathlatex);
$cmd = "$pathlatex --interaction=nonstopmode --halt-on-error $tex";
$output .= execute($cmd);

// step 2: dvips command
$pathdvips = escapeshellarg($pathdvips);
$cmd = "$pathdvips -E $dvi -o $ps";
$output .= execute($cmd);

// step 3: convert command
$pathconvert = escapeshellarg($pathconvert);
$cmd = "$pathconvert -density 240 -trim $ps $img ";
$output .= execute($cmd);

Expand Down

0 comments on commit 078379a

Please sign in to comment.