mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 14:40:00 +00:00
Support BitComet empty directories (ew)
This will allow most (if not all) torrents that have been rejected by 'Malformed torrent metadata (path part is empty)' Adjusts _validate_bytes to disable empty check Adds the empty check to file tree parsing
This commit is contained in:
parent
358c75036b
commit
4b4a7b9830
|
@ -100,6 +100,8 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False):
|
|||
for directory in path_parts:
|
||||
current_directory = current_directory.setdefault(directory, {})
|
||||
|
||||
# Don't add empty filenames (BitComet directory)
|
||||
if filename:
|
||||
current_directory[filename] = file_dict['length']
|
||||
|
||||
parsed_file_tree = utils.sorted_pathdict(parsed_file_tree)
|
||||
|
|
|
@ -280,7 +280,7 @@ class TorrentFileData(object):
|
|||
|
||||
def _validate_trackers(torrent_dict, tracker_to_check_for=None):
|
||||
announce = torrent_dict.get('announce')
|
||||
announce_string = _validate_bytes(announce, 'announce', 'utf-8')
|
||||
announce_string = _validate_bytes(announce, 'announce', test_decode='utf-8')
|
||||
|
||||
tracker_found = tracker_to_check_for and (
|
||||
announce_string.lower() == tracker_to_check_for.lower()) or False
|
||||
|
@ -292,7 +292,7 @@ def _validate_trackers(torrent_dict, tracker_to_check_for=None):
|
|||
for announce in announce_list:
|
||||
_validate_list(announce, 'announce-list item')
|
||||
|
||||
announce_string = _validate_bytes(announce[0], 'announce-list item url', 'utf-8')
|
||||
announce_string = _validate_bytes(announce[0], 'announce-list item url', test_decode='utf-8')
|
||||
if tracker_to_check_for and announce_string.lower() == tracker_to_check_for.lower():
|
||||
tracker_found = True
|
||||
|
||||
|
@ -308,7 +308,7 @@ def _validate_torrent_metadata(torrent_dict):
|
|||
assert isinstance(info_dict, dict), 'info is not a dict'
|
||||
|
||||
encoding_bytes = torrent_dict.get('encoding', b'utf-8')
|
||||
encoding = _validate_bytes(encoding_bytes, 'encoding', 'utf-8').lower()
|
||||
encoding = _validate_bytes(encoding_bytes, 'encoding', test_decode='utf-8').lower()
|
||||
|
||||
name = info_dict.get('name')
|
||||
_validate_bytes(name, 'name', test_decode=encoding)
|
||||
|
@ -330,16 +330,20 @@ def _validate_torrent_metadata(torrent_dict):
|
|||
|
||||
path_list = file_dict.get('path')
|
||||
_validate_list(path_list, 'path')
|
||||
for path_part in path_list:
|
||||
# Validate possible directory names
|
||||
for path_part in path_list[:-1]:
|
||||
_validate_bytes(path_part, 'path part', test_decode=encoding)
|
||||
# Validate actual filename, allow b'' to specify an empty directory
|
||||
_validate_bytes(path_list[-1], 'filename', check_empty=False, test_decode=encoding)
|
||||
|
||||
else:
|
||||
length = info_dict.get('length')
|
||||
_validate_number(length, 'length', check_positive=True)
|
||||
|
||||
|
||||
def _validate_bytes(value, name='value', test_decode=None):
|
||||
def _validate_bytes(value, name='value', check_empty=True, test_decode=None):
|
||||
assert isinstance(value, bytes), name + ' is not bytes'
|
||||
if check_empty:
|
||||
assert len(value) > 0, name + ' is empty'
|
||||
if test_decode:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue