10000 Example for replace_url · ada-url/ada-python@8556476 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8556476

Browse files
bbaylesanonrig
authored andcommitted
Example for replace_url
1 parent 81d7dd7 commit 8556476

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ It also provides some higher level functions for parsing and manipulating URLs.
4545
'search': '?q=1',
4646
'hash': '#2'
4747
}
48+
>>> ada_url.replace_url('http://example.org:80', protocol='https:')
49+
'https://example.org/'

ada_url/ada_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def replace_url(s, **kwargs):
304304

305305
for attr in URL_ATTRIBUTES:
306306
value = kwargs.get(attr)
307-
if not value:
307+
if value is None:
308308
continue
309309

310310
try:

tests/test_ada_url.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ def test_replace_url(self):
242242
actual = replace_url(s, **kwargs)
243243
self.assertEqual(actual, expected)
244244

245+
def test_replace_blank(self):
246+
s = 'https://user:pass@example.org'
247+
actual = replace_url(s, username='', password='')
248+
expected = 'https://example.org/'
249+
self.assertEqual(actual, expected)
250+
245251
def test_replace_href(self):
246252
s = 'https://username:password@www.google.com:8080/'
247253
kwargs = {

0 commit comments

Comments
 (0)
0