svn: /pear/packages/Net_URL2/trunk/ URL2.php tests/URL2Test.php
| From: | Till Klampaeckel | Date: | Sun, 13 Mar 2011 03:23:01 +0000 |
| Subject: | svn: /pear/packages/Net_URL2/trunk/ URL2.php tests/URL2Test.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-61423@lists.php.net to get a copy of this message | ||
till Sun, 13 Mar 2011 03:23:01 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=309155
Log:
* rebuild behavior for Net_URL2::OPTION_ENCODE_KEYS
* added two unit tests to verify
Changed paths:
U pear/packages/Net_URL2/trunk/URL2.php
U pear/packages/Net_URL2/trunk/tests/URL2Test.php
Modified: pear/packages/Net_URL2/trunk/URL2.php
===================================================================
--- pear/packages/Net_URL2/trunk/URL2.php 2011-03-13 02:53:52 UTC (rev 309154)
+++ pear/packages/Net_URL2/trunk/URL2.php 2011-03-13 03:23:01 UTC (rev 309155)
@@ -893,8 +893,11 @@
{
$query = array();
foreach ($data as $name => $value) {
+ if ($this->getOption(self::OPTION_ENCODE_KEYS) === true) {
+ $name = rawurlencode($name);
+ }
if ($key !== null) {
- $name = $key . '[' . rawurlencode($name) . ']';
+ $name = $key . '[' . $name . ']';
}
if (is_array($value)) {
$query[] = $this->buildQuery($value, $separator, $name);
Modified: pear/packages/Net_URL2/trunk/tests/URL2Test.php
===================================================================
--- pear/packages/Net_URL2/trunk/tests/URL2Test.php 2011-03-13 02:53:52 UTC (rev 309154)
+++ pear/packages/Net_URL2/trunk/tests/URL2Test.php 2011-03-13 03:23:01 UTC (rev 309155)
@@ -198,6 +198,40 @@
strval($url)
);
}
+
+ /**
+ * A test to verify that keys in QUERY_STRING are encoded by default.
+ *
+ * @return void
+ * @see Net_URL2::OPTION_ENCODE_KEYS
+ * @see Net_URL2::buildQuery()
+ */
+ public function testEncodeKeys()
+ {
+ $url = new Net_URL2('http://example.org');
+ $url->setQueryVariables(array('helgi rulez' => 'till too'));
+ $this->assertEquals(
+ 'http://example.org?helgi%20rulez=till%20too',
+ strval($url)
+ );
+ }
+
+ /**
+ * A test to verify that keys in QUERY_STRING are not encoded when we supply
+ * 'false' via {@link Net_URL2::__construct()}.
+ *
+ * @return void
+ * @see Net_URL2::OPTION_ENCODE_KEYS
+ * @see Net_URL2::buildQuery()
+ */
+ public function testDontEncodeKeys()
+ {
+ $url = new Net_URL2(
+ 'http://example.org',
+ array(Net_URL2::OPTION_ENCODE_KEYS => false)
+ );
+ $url->setQueryVariables(array('till rulez' => 'helgi too'));
+ }
}
// Call Net_URL2Test::main() if this source file is executed directly.