Sergey Schetinin avatar Sergey Schetinin committed 5531a94

handle the case when environ is missing the SCRIPT_NAME key ( )

Comments (0)

Files changed (3)


 def test_req_kw_none_val():
     assert 'content-length' not in Request({}, content_length=None).headers
     assert 'content-type' not in Request({}, content_type=None).headers
+def test_env_keys():
+    req = Request.blank('/')
+    # SCRIPT_NAME can be missing
+    del req.environ['SCRIPT_NAME']
+    eq_(req.script_name, '')
+    eq_(req.uscript_name, u'')


 def upath_property(key):
     def fget(req):
-        return req.environ[key].decode('UTF8', req.unicode_errors)
+        return req.environ.get(key, '').decode('UTF8', req.unicode_errors)
     def fset(req, val):
         req.environ[key] = val.encode('UTF8', req.unicode_errors)
     return property(fget, fset, doc='upath_property(%r)' % key)
     scheme = environ_getter('wsgi.url_scheme')
     method = environ_getter('REQUEST_METHOD')
-    script_name = environ_getter('SCRIPT_NAME')
+    script_name = environ_getter('SCRIPT_NAME', '')
     path_info = environ_getter('PATH_INFO')
     content_length = converter(
         environ_getter('CONTENT_LENGTH', None, '14.13'),
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
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.