-* 1.15.2 (2014-XX-XX)
+* 1.16.0 (2014-XX-XX)
+ * changed url_encode to always encode according to RFC 3986
* fixed inheritance in a 'use'-hierarchy
* removed the __toString policy check when the sandbox is disabled
* fixed recursively calling blocks in templates with inheritance
},
"extra": {
"branch-alias": {
- "dev-master": "1.15-dev"
+ "dev-master": "1.16-dev"
}
}
}
.. versionadded:: 1.12.3
Support for encoding an array as query string was added in Twig 1.12.3.
+.. versionadded:: 1.16.0
+ The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes
+ according to RFC 3986.
+
The ``url_encode`` filter percent encodes a given string as URL segment
or an array as query string:
{{ "path-seg*ment"|url_encode }}
{# outputs "path-seg%2Ament" #}
- {{ "string with spaces"|url_encode(true) }}
+ {{ "string with spaces"|url_encode }}
{# outputs "string%20with%20spaces" #}
{{ {'param': 'value', 'foo': 'bar'}|url_encode }}
.. note::
Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass
- ``true`` as the first parameter) or the `http_build_query`_ function.
+ ``true`` as the first parameter) or the `http_build_query`_ function. Note
+ that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the
+ ``raw`` argument was removed.)
.. _`urlencode`: http://php.net/urlencode
.. _`rawurlencode`: http://php.net/rawurlencode
#ifndef PHP_TWIG_H
#define PHP_TWIG_H
-#define PHP_TWIG_VERSION "1.15.2-DEV"
+#define PHP_TWIG_VERSION "1.16.0-DEV"
#include "php.h"
*/
class Twig_Environment
{
- const VERSION = '1.15.2-DEV';
+ const VERSION = '1.16.0-DEV';
protected $charset;
protected $loader;
}
/**
- * URL encodes a string as a path segment or an array as a query string.
+ * URL encodes (RFC 3986) a string as a path segment or an array as a query string.
*
* @param string|array $url A URL or an array of query parameters
*
function twig_urlencode_filter($url)
{
if (is_array($url)) {
+ if (defined('PHP_QUERY_RFC3986')) {
+ return http_build_query($url, '', '&', PHP_QUERY_RFC3986);
+ }
+
return http_build_query($url, '', '&');
}
--TEST--
"url_encode" filter
+--CONDITION--
+defined('PHP_QUERY_RFC3986')
--TEMPLATE--
{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode }}
{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode|raw }}
{{ {}|url_encode|default("default") }}
+{{ 'spéßi%le%c0d@dspa ce'|url_encode }}
--DATA--
return array()
--EXPECT--
-foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa+ce=
-foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa+ce=
+foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce=
+foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce=
default
+sp%C3%A9%C3%9Fi%25le%25c0d%40dspa%20ce
--- /dev/null
+--TEST--
+"url_encode" filter for PHP < 5.4 and HHVM
+--CONDITION--
+defined('PHP_QUERY_RFC3986')
+--TEMPLATE--
+{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode }}
+{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode|raw }}
+{{ {}|url_encode|default("default") }}
+{{ 'spéßi%le%c0d@dspa ce'|url_encode }}
+--DATA--
+return array()
+--EXPECT--
+foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce=
+foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce=
+default
+sp%C3%A9%C3%9Fi%25le%25c0d%40dspa%20ce