File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -271,7 +271,11 @@ def __str__(self):
271271 return self .href
272272
273273 def __repr__ (self ):
274- return f'<URL "{ self .href } ">'
274+ password = self .password
275+ self .password = ''
276+ ret = f'<URL "{ self .href } ">'
277+ self .password = password
278+ return ret
275279
276280 @staticmethod
277281 def can_parse (url : str , base : Optional [str ] = None ) -> bool :
@@ -755,5 +759,6 @@ def encode(s: Union[str, bytes]) -> bytes:
755759
756760idna_to_ascii = idna .encode
757761
762+
758763def get_version ():
759764 return ffi .string (lib .ada_get_version ()).decode ()
Original file line number Diff line number Diff line change @@ -194,6 +194,15 @@ def test_to_repr(self):
194194 expected = '<URL "https://example.org/something.txt">'
195195 self .assertEqual (actual , expected )
196196
197+ def test_to_repr_password (self ):
198+ # Redact the password attribute from __repr__, but keep it on the object.
199+ urlobj = URL ('https://user:password1@example.org/../something.txt' )
200+ self .assertEqual (repr (urlobj ), '<URL "https://user@example.org/something.txt">' )
201+ self .assertEqual (urlobj .password , 'password1' )
202+ self .assertEqual (
203+ str (urlobj ), 'https://user:password1@example.org/something.txt'
204+ )
205+
197206 def test_check_url (self ):
198207 for s , expected in (
199208 ('https:example.org' , True ),
@@ -555,6 +564,6 @@ class GetVersionTests(TestCase):
555564 def test_get_version (self ):
556565 value = get_version ()
557566 version_parts = value .split ('.' )
558- self .assertEqual (len (version_parts ), 3 ) # Three parts
567+ self .assertEqual (len (version_parts ), 3 ) # Three parts
559568 int (version_parts [0 ]) # Major should be an integer
560569 int (version_parts [1 ]) # Minor should be an integer
You can’t perform that action at this time.
0 commit comments