@@ -219,6 +219,17 @@ def test_safe_url_port_number(self):
219219 safe_url_string (u"http://www.example.com:/résumé?q=résumé" ),
220220 "http://www.example.com/r%C3%A9sum%C3%A9?q=r%C3%A9sum%C3%A9" )
221221
222+ def test_safe_url_string_preserve_nonfragment_hash (self ):
223+ # don't decode `%23` to `#`
224+ self .assertEqual (safe_url_string ("http://www.example.com/path/to/%23/foo/bar" ),
225+ "http://www.example.com/path/to/%23/foo/bar" )
226+ self .assertEqual (safe_url_string ("http://www.example.com/path/to/%23/foo/bar#frag" ),
227+ "http://www.example.com/path/to/%23/foo/bar#frag" )
228+ self .assertEqual (safe_url_string ("http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2Fpath%2Fto%2F%23%2Fbar%2Ffoo" ),
229+ "http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2Fpath%2Fto%2F%23%2Fbar%2Ffoo" )
230+ self .assertEqual (safe_url_string ("http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2F%2Fpath%2Fto%2F%23%2Fbar%2Ffoo#frag" ),
231+ "http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2F%2Fpath%2Fto%2F%23%2Fbar%2Ffoo#frag" )
232+
222233 def test_safe_download_url (self ):
223234 self .assertEqual (safe_download_url ('http://www.example.org' ),
224235 'http://www.example.org/' )
@@ -650,6 +661,21 @@ def test_canonicalize_url_idna_exceptions(self):
650661 "http://www.{label}.com/r%C3%A9sum%C3%A9?q=r%C3%A9sum%C3%A9" .format (
651662 label = u"example" * 11 ))
652663
664+ def test_preserve_nonfragment_hash (self ):
665+ # don't decode `%23` to `#`
666+ self .assertEqual (canonicalize_url ("http://www.example.com/path/to/%23/foo/bar" ),
667+ "http://www.example.com/path/to/%23/foo/bar" )
668+ self .assertEqual (canonicalize_url ("http://www.example.com/path/to/%23/foo/bar#frag" ),
669+ "http://www.example.com/path/to/%23/foo/bar" )
670+ self .assertEqual (canonicalize_url ("http://www.example.com/path/to/%23/foo/bar#frag" , keep_fragments = True ),
671+ "http://www.example.com/path/to/%23/foo/bar#frag" )
672+ self .assertEqual (canonicalize_url ("http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2Fpath%2Fto%2F%23%2Fbar%2Ffoo" ),
673+ "http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2Fpath%2Fto%2F%23%2Fbar%2Ffoo" )
674+ self .assertEqual (canonicalize_url ("http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2F%2Fpath%2Fto%2F%23%2Fbar%2Ffoo#frag" ),
675+ "http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2F%2Fpath%2Fto%2F%23%2Fbar%2Ffoo" )
676+ self .assertEqual (canonicalize_url ("http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2F%2Fpath%2Fto%2F%23%2Fbar%2Ffoo#frag" , keep_fragments = True ),
677+ "http://www.example.com/path/to/%23/foo/bar?url=http%3A%2F%2Fwww.example.com%2F%2Fpath%2Fto%2F%23%2Fbar%2Ffoo#frag" )
678+
653679
654680class DataURITests (unittest .TestCase ):
655681
0 commit comments