Mike Orr avatar Mike Orr committed 59054a8

Urlencode ``urlify()`` return value in case it contains "?".

Comments (0)

Files changed (3)

   - Preserve case of "method" arg in ``button_to()`` for XHTML compatibility. 
     Patch by transducer.
 
+* webhelpers.text:
+
+  - Urlencode ``urlify()`` return value in case it contains special
+    characters like "?". Reported by mcd34@gmail.com.
+
 1.1 (2010-08-09)
 ----------------
 

tests/test_text.py

         eq_(control, strip_leading_whitespace(s))
 
     # @@MO wrap_paragraphs untested.
+
+    def test_urlify(self):
+        s = "What is this? It is a car."
+        control = "What%20is%20this%3f%20It%20is%20a%20car."

webhelpers/text.py

 
 import re
 import textwrap
+import urllib
 
 from webhelpers.html.tools import strip_tags
 
 
     Based on Ruby's stringex package
     (http://github.com/rsl/stringex/tree/master)
+
+    Changed in WebHelpers 1.2: urlecode the result in case it contains special
+    characters like "?". 
     """
     s = remove_formatting(string).lower()
     s = replace_whitespace(s, '-')
-    return collapse(s, '-')
+    s = collapse(s, '-')
+    return urllib.quote(s)
 
 
 def remove_formatting(string):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.