Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support a None value in query string parameters

  • Loading branch information...
commit af5fa07ca2fcc48ab357c0db4e1301bb960addca 1 parent b731b5f
@mmerickel mmerickel authored
Showing with 24 additions and 0 deletions.
  1. +10 −0 CHANGES.txt
  2. +6 −0 pyramid/encode.py
  3. +8 −0 pyramid/tests/test_encode.py
View
10 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)
==================
View
6 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)
View
8 pyramid/tests/test_encode.py
@@ -41,6 +41,14 @@ def test_dict(self):
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
Please sign in to comment.
Something went wrong with that request. Please try again.