summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt10
-rw-r--r--pyramid/encode.py6
-rw-r--r--pyramid/tests/test_encode.py8
3 files changed, 24 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 8b2210a99..e972c08c3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,6 +6,16 @@ Documentation
- Added a "Quick Tutorial" to go with the Quick Tour
+Backwards Incompatibilities
+---------------------------
+
+- The key/values in the ``_query`` parameter of ``request.route_url`` and the
+ ``query`` parameter of ``request.resource_url`` (and their variants), used
+ to encode a value of ``None`` as the string ``'None'``, leaving the resulting
+ query string to be ``a=b&key=None``. The value is now dropped in this
+ situation, leaving a query string of ``a=b&key``.
+ See https://github.com/Pylons/pyramid/issues/1119
+
1.5a2 (2013-09-22)
==================
diff --git a/pyramid/encode.py b/pyramid/encode.py
index 65bc95032..9341f7665 100644
--- a/pyramid/encode.py
+++ b/pyramid/encode.py
@@ -32,6 +32,10 @@ def urlencode(query, doseq=True):
See the Python stdlib documentation for ``urllib.urlencode`` for
more information.
+
+ .. versionchanged:: 1.5
+ In a key/value pair, if the value is ``None`` then it will be
+ dropped from the resulting output.
"""
try:
# presumed to be a dictionary
@@ -50,6 +54,8 @@ def urlencode(query, doseq=True):
x = _enc(x)
result += '%s%s=%s' % (prefix, k, x)
prefix = '&'
+ elif v is None:
+ result += '%s%s' % (prefix, k)
else:
v = _enc(v)
result += '%s%s=%s' % (prefix, k, v)
diff --git a/pyramid/tests/test_encode.py b/pyramid/tests/test_encode.py
index 736ecb5b3..1e0ecbe20 100644
--- a/pyramid/tests/test_encode.py
+++ b/pyramid/tests/test_encode.py
@@ -41,6 +41,14 @@ class UrlEncodeTests(unittest.TestCase):
result = self._callFUT({'a':1})
self.assertEqual(result, 'a=1')
+ def test_None_value(self):
+ result = self._callFUT([('a', None)])
+ self.assertEqual(result, 'a')
+
+ def test_None_value_with_prefix(self):
+ result = self._callFUT([('a', '1'), ('b', None)])
+ self.assertEqual(result, 'a=1&b')
+
class URLQuoteTests(unittest.TestCase):
def _callFUT(self, val, safe=''):
from pyramid.encode import url_quote