Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ada_url/ada_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ def __str__(self):
return self.href

def __repr__(self):
return f'<URL "{self.href}">'
password = self.password
self.password = ''
ret = f'<URL "{self.href}">'
self.password = password
Comment on lines +274 to +277
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very thread-unsafe to me. 😅 __repr__ usually isn't used in hot loops, so a copy should be fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll switch to copying in this PR:
#128

return ret

@staticmethod
def can_parse(url: str, base: Optional[str] = None) -> bool:
Expand Down Expand Up @@ -755,5 +759,6 @@ def encode(s: Union[str, bytes]) -> bytes:

idna_to_ascii = idna.encode


def get_version():
return ffi.string(lib.ada_get_version()).decode()
11 changes: 10 additions & 1 deletion tests/test_ada_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def test_to_repr(self):
expected = '<URL "https://example.org/something.txt">'
self.assertEqual(actual, expected)

def test_to_repr_password(self):
# Redact the password attribute from __repr__, but keep it on the object.
urlobj = URL('https://user:password1@example.org/../something.txt')
self.assertEqual(repr(urlobj), '<URL "https://user@example.org/something.txt">')
self.assertEqual(urlobj.password, 'password1')
self.assertEqual(
str(urlobj), 'https://user:password1@example.org/something.txt'
)

def test_check_url(self):
for s, expected in (
('https:example.org', True),
Expand Down Expand Up @@ -555,6 +564,6 @@ class GetVersionTests(TestCase):
def test_get_version(self):
value = get_version()
version_parts = value.split('.')
self.assertEqual(len(version_parts), 3) # Three parts
self.assertEqual(len(version_parts), 3) # Three parts
int(version_parts[0]) # Major should be an integer
int(version_parts[1]) # Minor should be an integer
Loading