wfEscapeShellArg() can handle multiple params, escaping each. This patch changes wfShellExec() to call wfEscapeShellArg() directly instead of doing the gluing itself. This patch also extends wfEscapeShellArg() to accept an array parameter optionally instead of as separate args, which is often useful. Added also unit test cases for single, multiple args, and single array args. Change-Id: I7a0761cc2ba98c210a9eacadd12da407d933e42a
43 lines
869 B
PHP
43 lines
869 B
PHP
<?php
|
|
|
|
/**
|
|
* @group GlobalFunctions
|
|
* @covers ::wfEscapeShellArg
|
|
*/
|
|
class wfEscapeShellArgTest extends MediaWikiTestCase {
|
|
public function testSingleInput() {
|
|
if ( wfIsWindows() ) {
|
|
$expected = '"blah"';
|
|
} else {
|
|
$expected = "'blah'";
|
|
}
|
|
|
|
$actual = wfEscapeShellArg( 'blah' );
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
}
|
|
|
|
public function testMultipleArgs() {
|
|
if ( wfIsWindows() ) {
|
|
$expected = '"foo" "bar" "baz"';
|
|
} else {
|
|
$expected = "'foo' 'bar' 'baz'";
|
|
}
|
|
|
|
$actual = wfEscapeShellArg( 'foo', 'bar', 'baz' );
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
}
|
|
|
|
public function testMultipleArgsAsArray() {
|
|
if ( wfIsWindows() ) {
|
|
$expected = '"foo" "bar" "baz"';
|
|
} else {
|
|
$expected = "'foo' 'bar' 'baz'";
|
|
}
|
|
|
|
$actual = wfEscapeShellArg( array( 'foo', 'bar', 'baz' ) );
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
}
|
|
}
|