Skip to content

Commit

Permalink
[networking] Strip whitespace around header values (yt-dlp#8802)
Browse files Browse the repository at this point in the history
Fixes yt-dlp#8729
Authored by: coletdjnz
  • Loading branch information
coletdjnz authored Dec 20, 2023
1 parent db8b4ed commit 196eb0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,11 @@ def test_http_header_dict(self):
headers4 = HTTPHeaderDict({'ytdl-test': 'data;'})
self.assertEqual(set(headers4.items()), {('Ytdl-Test', 'data;')})

# common mistake: strip whitespace from values
# https://github.com/yt-dlp/yt-dlp/issues/8729
headers5 = HTTPHeaderDict({'ytdl-test': ' data; '})
self.assertEqual(set(headers5.items()), {('Ytdl-Test', 'data;')})

def test_extract_basic_auth(self):
assert extract_basic_auth('http://:foo.bar') == ('http://:foo.bar', None)
assert extract_basic_auth('http://foo.bar') == ('http://foo.bar', None)
Expand Down
2 changes: 1 addition & 1 deletion yt_dlp/utils/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, *args, **kwargs):
def __setitem__(self, key, value):
if isinstance(value, bytes):
value = value.decode('latin-1')
super().__setitem__(key.title(), str(value))
super().__setitem__(key.title(), str(value).strip())

def __getitem__(self, key):
return super().__getitem__(key.title())
Expand Down

0 comments on commit 196eb0f

Please sign in to comment.