svn: /pear/packages/URI_Template/trunk/ Template.php tests/URI/Template/TemplateTest.php
| From: | Martin Jansen | Date: | Mon, 21 Dec 2009 20:46:26 +0000 |
| Subject: | svn: /pear/packages/URI_Template/trunk/ Template.php tests/URI/Template/TemplateTest.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-58341@lists.php.net to get a copy of this message | ||
mj Mon, 21 Dec 2009 20:46:26 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=292440
Log:
Implemented Feature Request #15384: Make rawurlencode optional.
Bug: http://pear.php.net/bugs/15384 (unknown)
Changed paths:
U pear/packages/URI_Template/trunk/Template.php
U pear/packages/URI_Template/trunk/tests/URI/Template/TemplateTest.php
Modified: pear/packages/URI_Template/trunk/Template.php
===================================================================
--- pear/packages/URI_Template/trunk/Template.php 2009-12-21 20:46:21 UTC (rev 292439)
+++ pear/packages/URI_Template/trunk/Template.php 2009-12-21 20:46:26 UTC (rev 292440)
@@ -74,9 +74,13 @@
*
* @param array $values Associative array with replacements for the
* variables in the expansions
+ * @param boolean $URLencode Boolean variable determing if the replacements
+ * should be encoded according to RFC 1738 or
+ * or not. Default is true, i.e. the replacements
+ * are encoded.
* @return string URI
*/
- public function substitute($values)
+ public function substitute($values, $URLencode = true)
{
/* We need to assign $values to an object member because it is needed
* in self::_substitute().
@@ -86,11 +90,13 @@
/* Because it is common that a template contains several replacements,
* we do the URL encoding here instead of in _substitute.
*/
- foreach ($this->values as &$value) {
- if (is_array($value)) {
- $value = array_map('rawurlencode', $value);
- } else {
- $value = rawurlencode($value);
+ if ($URLencode) {
+ foreach ($this->values as &$value) {
+ if (is_array($value)) {
+ $value = array_map('rawurlencode', $value);
+ } else {
+ $value = rawurlencode($value);
+ }
}
}
Modified: pear/packages/URI_Template/trunk/tests/URI/Template/TemplateTest.php
===================================================================
--- pear/packages/URI_Template/trunk/tests/URI/Template/TemplateTest.php 2009-12-21 20:46:21 UTC
(rev 292439)
+++ pear/packages/URI_Template/trunk/tests/URI/Template/TemplateTest.php 2009-12-21 20:46:26 UTC
(rev 292440)
@@ -76,7 +76,19 @@
self::runnerHelper($tests);
}
+
+ public function testSubstituteSansURLEncoding() {
+ $t = new URI_Template("{foo}");
+ $result = $t->substitute(array("foo" => "%s"), false);
+ self::assertEquals("%s", $result);
+ $result = $t->substitute(array("foo" => "%s"), true);
+ self::assertEquals("%25s", $result);
+
+ $result = $t->substitute(array("foo" => "%s"));
+ self::assertEquals("%25s", $result);
+ }
+
public function testGetTemplateVariables() {
$tests = array(
"/{-suffix|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b}" =>
array("a", "points", "b"),