From f6e119d372e321b58bc691ce13bfbd87e27b20f4 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 4 Jun 2012 16:05:26 +0400 Subject: [PATCH] modified GetViewHelper to return urlencoded GET query params --- tests/view/helpers/GetViewHelperTest.php | 9 +++++++++ view/helpers/GetViewHelper.php | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/view/helpers/GetViewHelperTest.php b/tests/view/helpers/GetViewHelperTest.php index 73c43f1..dac3f28 100644 --- a/tests/view/helpers/GetViewHelperTest.php +++ b/tests/view/helpers/GetViewHelperTest.php @@ -68,5 +68,14 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase $result = $this->helper->get(array('b' => 'c', 'c' => array('five' => 'six'))); $this->assertSame('?a[one]=1&a[two]=2&b=c&c[five]=six', $result); } + + public function testGetUrlencode() + { + $_GET['a'] = array('one' => 1, 'two' => 2); + $_GET['b'] = 'a'; + $_GET['c'] = array('three' => 'four'); + $result = $this->helper->get(array('b' => 'c d e', 'c' => array('five' => 'six seven'))); + $this->assertSame('?a[one]=1&a[two]=2&b=c+d+e&c[five]=six+seven', $result); + } } diff --git a/view/helpers/GetViewHelper.php b/view/helpers/GetViewHelper.php index d28e325..78cb75a 100644 --- a/view/helpers/GetViewHelper.php +++ b/view/helpers/GetViewHelper.php @@ -46,11 +46,11 @@ class GetViewHelper extends ViewHelper if (is_array($value)){ $result = array(); foreach ($value as $key => $val) { - $result[] = $name . '[' . $key . ']=' . $val; + $result[] = $name . '[' . $key . ']=' . urlencode($val); } $result = implode('&', $result); } else { - $result = $name . '=' . $value; + $result = $name . '=' . urlencode($value); } return $result; }