diff --git a/app/models/Command.php b/app/models/Command.php index 2c85e61..5c4a71b 100644 --- a/app/models/Command.php +++ b/app/models/Command.php @@ -96,6 +96,7 @@ public function applySwitches($switches) { $url = $this->url; $urlencodeValues = true; $rawurlencodeValues = false; + $spaceReplacement = null; if (strpos($url, '[no url encoding]') !== false) { $url = str_replace('[no url encoding]', '', $url); $urlencodeValues = false; @@ -103,8 +104,14 @@ public function applySwitches($switches) { $url = str_replace('[use %20 for spaces]', '', $url); $rawurlencodeValues = true; $urlencodeValues = false; + } elseif (preg_match('/\[use (.{1,4}) for spaces\]/', $url, $matches)) { + $url = str_replace($matches[0], '', $url); + $spaceReplacement = $matches[1]; } foreach ($switches as $name => $value) { + if ($spaceReplacement !== null) { + $value = str_replace(' ', $spaceReplacement, $value); + } if ($urlencodeValues) { $value = urlencode($value); } elseif ($rawurlencodeValues) { diff --git a/test/CommandTest.php b/test/CommandTest.php index 36d29ae..5eca8b2 100644 --- a/test/CommandTest.php +++ b/test/CommandTest.php @@ -94,5 +94,11 @@ public function testApplySwitches_UsesPercent20ForSpaces() { $this->assertSame('http://google.com/?a=A%20B', $url); } + public function testApplySwitches_UsesXForSpaces() { + $this->command->url = 'http://google.com/?a=%s[use X for spaces]'; + $url = $this->command->applySwitches(array('%s' => 'A B')); + $this->assertSame('http://google.com/?a=AXB', $url); + } + } diff --git a/test/ControllerTest.php b/test/ControllerTest.php index 28431fc..a92d599 100644 --- a/test/ControllerTest.php +++ b/test/ControllerTest.php @@ -5,7 +5,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->controller = new TestController(null); + $this->controller = new TestController(null, null); } public function testGetName() { diff --git a/test/bootstrap.php b/test/bootstrap.php index 0ebff66..3408f17 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -4,3 +4,4 @@ * * Usage: phpunit --bootstrap test/bootstrap.php test */ +require_once 'app/helpers/functions.php';