@@ -569,6 +569,36 @@ def test_telurl_params(self):
569569 self .assertEqual (p1 .params , 'phone-context=+1-914-555' )
570570
571571
572+ def test_urlsplit_remove_unsafe_bytes (self ):
573+ # Remove ASCII tabs and newlines from input
574+ url = "http://www.python.org/java\n script:\t alert('msg\r \n ')/#frag"
575+ p = urlparse .urlsplit (url )
576+ self .assertEqual (p .scheme , "http" )
577+ self .assertEqual (p .netloc , "www.python.org" )
578+ self .assertEqual (p .path , "/javascript:alert('msg')/" )
579+ self .assertEqual (p .query , "" )
580+ self .assertEqual (p .fragment , "frag" )
581+ self .assertEqual (p .username , None )
582+ self .assertEqual (p .password , None )
583+ self .assertEqual (p .hostname , "www.python.org" )
584+ self .assertEqual (p .port , None )
585+ self .assertEqual (p .geturl (), "http://www.python.org/javascript:alert('msg')/#frag" )
586+
587+ # Remove ASCII tabs and newlines from input as unicode.
588+ url = u"http://www.python.org/java\n script:\t alert('msg\r \n ')/#frag"
589+ p = urlparse .urlsplit (url )
590+ self .assertEqual (p .scheme , u"http" )
591+ self .assertEqual (p .netloc , u"www.python.org" )
592+ self .assertEqual (p .path , u"/javascript:alert('msg')/" )
593+ self .assertEqual (p .query , u"" )
594+ self .assertEqual (p .fragment , u"frag" )
595+ self .assertEqual (p .username , None )
596+ self .assertEqual (p .password , None )
597+ self .assertEqual (p .hostname , u"www.python.org" )
598+ self .assertEqual (p .port , None )
599+ self .assertEqual (p .geturl (), u"http://www.python.org/javascript:alert('msg')/#frag" )
600+
601+
572602 def test_attributes_bad_port (self ):
573603 """Check handling of non-integer ports."""
574604 p = urlparse .urlsplit ("http://www.example.net:foo" )
0 commit comments