summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2013-10-02 16:46:02 -0400
committerChris McDonough <chrism@plope.com>2013-10-02 16:46:02 -0400
commit39f91d2c2f334eed78d294549a8c654da0a035e4 (patch)
tree6378ffdffd1ca02186e691161271164148786d64
parenta2d4c260952a8e2329df0c4a66d7239f2e8d0652 (diff)
parent15afe5e7fb5dafa570faf055eb4b4a4518349409 (diff)
downloadpyramid-39f91d2c2f334eed78d294549a8c654da0a035e4.tar.gz
pyramid-39f91d2c2f334eed78d294549a8c654da0a035e4.tar.bz2
pyramid-39f91d2c2f334eed78d294549a8c654da0a035e4.zip
Merge branch 'fix.none-value-in-query-string'
-rw-r--r--CHANGES.txt10
-rw-r--r--pyramid/encode.py6
-rw-r--r--pyramid/tests/test_encode.py12
3 files changed, 28 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index cb28d880b..67cefb79a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -23,6 +23,16 @@ Documentation
- Removed mention of ``pyramid_beaker`` from docs. Beaker is no longer
maintained. Point people at ``pyramid_redis_sessions`` instead.
+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..9e190bc21 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..908249877 100644
--- a/pyramid/tests/test_encode.py
+++ b/pyramid/tests/test_encode.py
@@ -41,6 +41,18 @@ 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=')
+
+ def test_None_value_with_prefix_values(self):
+ result = self._callFUT([('a', '1'), ('b', None), ('c', None)])
+ self.assertEqual(result, 'a=1&b=&c=')
+
class URLQuoteTests(unittest.TestCase):
def _callFUT(self, val, safe=''):
from pyramid.encode import url_quote