mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-22 06:00:00 +00:00
[networking] Strip whitespace around header values (#8802)
Fixes https://github.com/yt-dlp/yt-dlp/issues/8729 Authored by: coletdjnz
This commit is contained in:
parent
db8b4edc7d
commit
196eb0fe77
2 changed files with 6 additions and 1 deletions
|
@ -2370,6 +2370,11 @@ def test_http_header_dict(self):
|
||||||
headers4 = HTTPHeaderDict({'ytdl-test': 'data;'})
|
headers4 = HTTPHeaderDict({'ytdl-test': 'data;'})
|
||||||
self.assertEqual(set(headers4.items()), {('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):
|
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)
|
||||||
assert extract_basic_auth('http://foo.bar') == ('http://foo.bar', None)
|
assert extract_basic_auth('http://foo.bar') == ('http://foo.bar', None)
|
||||||
|
|
|
@ -67,7 +67,7 @@ def __init__(self, *args, **kwargs):
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
value = value.decode('latin-1')
|
value = value.decode('latin-1')
|
||||||
super().__setitem__(key.title(), str(value))
|
super().__setitem__(key.title(), str(value).strip())
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return super().__getitem__(key.title())
|
return super().__getitem__(key.title())
|
||||||
|
|
Loading…
Reference in a new issue