Ticket #5236: my-twisted-patch.patch

File my-twisted-patch.patch, 1.2 KB (added by moijes12, 2 years ago)

Check added to function twisted.web.util.redirectTo so that it raises TypeError if Unicode object passed in URL. Unit test file test_util is also updated with unit test.Comments and docstring are added and test has passed.

  • twisted/web/util.py

     
    1414 
    1515 
    1616def redirectTo(URL, request): 
     17    # Patch for #5236 
     18    # If Unicode object is passed in URL, redirectTo raises TypeError 
     19    if isinstance(URL, unicode) : 
     20        raise TypeError("Unicode object not allowed as URL") 
    1721    request.setHeader("content-type", "text/html; charset=utf-8") 
    1822    request.redirect(URL) 
    1923    return """ 
  • twisted/web/test/test_util.py

     
    7373            request.responseHeaders.getRawHeaders('content-type'), 
    7474            ['text/html; charset=utf-8']) 
    7575 
    76  
     76    def test_redirectToUnicodeURL(self) : 
     77        """ 
     78        L{redirectTo} will raise TypeError if unicode object is passed in URL 
     79        """   
     80        request = Request(DummyChannel(), True) 
     81        request.method = 'GET' 
     82        targetURL = u'http://target.example.com/4321' 
     83        self.assertRaises(TypeError, redirectTo, targetURL, request)