r103473 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103472‎ | r103473 | r103474 >
Date:16:25, 17 November 2011
Author:platonides
Status:ok (Comments)
Tags:
Comment:
wfEscapeSingleQuotes() change proposed by Ralf Lederle in
https://bugzilla.wikimedia.org/show_bug.cgi?id=13518#c11
For Bug 13518 - <math> does not work (wrong shell escaping under Windows)
Modified paths:
  • /trunk/extensions/Math/Math.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Math/Math.body.php
@@ -10,6 +10,17 @@
1111 * @ingroup Parser
1212 */
1313
 14+if ( !function_exists('wfEscapeSingleQuotes') ) {
 15+ /**
 16+ * Escapes a string with single quotes for a UNIX shell.
 17+ * It's equivalente to escapeshellarg() in UNIX, but also
 18+ * working in Windows, where we need it for cygwin shell.
 19+ */
 20+ function wfEscapeSingleQuotes( $str ) {
 21+ return "'" . str_replace( "'", "'\\''", $str ) . "'";
 22+ }
 23+}
 24+
1425 /**
1526 * Takes LaTeX fragments, sends them to a helper program (texvc) for rendering
1627 * to rasterized PNG and HTML and MathML approximations. An appropriate
@@ -65,11 +76,11 @@
6677 return $this->_error( 'math_notexvc' );
6778 }
6879 $cmd = $wgTexvc . ' ' .
69 - escapeshellarg( $wgTmpDirectory ).' '.
70 - escapeshellarg( $wgTmpDirectory ).' '.
71 - escapeshellarg( $this->tex ).' '.
72 - escapeshellarg( 'UTF-8' ).' '.
73 - escapeshellarg( $wgTexvcBackgroundColor );
 80+ wfEscapeSingleQuotes( $wgTmpDirectory ) . ' '.
 81+ wfEscapeSingleQuotes( $wgTmpDirectory ) . ' '.
 82+ wfEscapeSingleQuotes( $this->tex ) . ' '.
 83+ wfEscapeSingleQuotes( 'UTF-8' ) . ' '.
 84+ wfEscapeSingleQuotes( $wgTexvcBackgroundColor );
7485
7586 if ( wfIsWindows() ) {
7687 # Invoke it within cygwin sh, because texvc expects sh features in its default shell

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r40753Use wfEscapeShellArg() since it works on windows (bug 13518)aaron15:10, 12 September 2008

Comments

#Comment by Nikerabbit (talk | contribs)   13:52, 18 November 2011

How does this relate to wfEscapeShellArg in global functions?

#Comment by Platonides (talk | contribs)   16:42, 15 December 2011

wfEscapeShellArg() escapes a command for the native environment. However, texvc apparently expects a posix shell, so it needs Unix quoting (which on the next line, not showed in the excerpt get escaped with wfEscapeShellArg for passing from cmd.exe to sh.exe)

Status & tagging log