mirror of
https://github.com/ciromattia/kcc
synced 2026-10-18 07:22:33 +00:00
Fix volume input validation in bulk metadata editor
* Handle invalid range formats like "1-2-3" or "--" that previously fell through, now returns an error message * Add explicit check for empty/malformed range parts before attempting to parse * Add positive number validation for all input types (range, comma-list, single number) to be consistent with single file mode which uses isnumeric() * Add explicit validation for empty volumes list after parsing
This commit is contained in:
@@ -1599,32 +1599,40 @@ class KCCGUI_MetaEditor(KCC_ui_editor.Ui_editorDialog):
|
|||||||
# Check if it's a range (e.g., "5-10")
|
# Check if it's a range (e.g., "5-10")
|
||||||
if '-' in text and ',' not in text:
|
if '-' in text and ',' not in text:
|
||||||
parts = text.split('-')
|
parts = text.split('-')
|
||||||
if len(parts) == 2:
|
if len(parts) != 2 or not parts[0].strip() or not parts[1].strip():
|
||||||
try:
|
return None, 'Invalid range format (use start-end)'
|
||||||
start = int(parts[0].strip())
|
try:
|
||||||
end = int(parts[1].strip())
|
start = int(parts[0].strip())
|
||||||
if start <= end:
|
end = int(parts[1].strip())
|
||||||
volumes = list(range(start, end + 1))
|
if start < 0 or end < 0:
|
||||||
else:
|
return None, 'Volume numbers must be positive'
|
||||||
return None, 'Invalid range: start > end'
|
if start > end:
|
||||||
except ValueError:
|
return None, 'Invalid range: start > end'
|
||||||
return None, 'Invalid range format'
|
volumes = list(range(start, end + 1))
|
||||||
|
except ValueError:
|
||||||
|
return None, 'Invalid range format'
|
||||||
# Check if it's a comma-separated list (e.g., "1,3,5")
|
# Check if it's a comma-separated list (e.g., "1,3,5")
|
||||||
elif ',' in text:
|
elif ',' in text:
|
||||||
try:
|
try:
|
||||||
volumes = [int(v.strip()) for v in text.split(',') if v.strip()]
|
volumes = [int(v.strip()) for v in text.split(',') if v.strip()]
|
||||||
|
if any(v < 0 for v in volumes):
|
||||||
|
return None, 'Volume numbers must be positive'
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None, 'Invalid list format'
|
return None, 'Invalid list format'
|
||||||
# Single number - generate sequence starting from that number
|
# Single number - generate sequence starting from that number
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
start = int(text)
|
start = int(text)
|
||||||
|
if start < 0:
|
||||||
|
return None, 'Volume number must be positive'
|
||||||
volumes = list(range(start, start + fileCount))
|
volumes = list(range(start, start + fileCount))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None, 'Invalid number'
|
return None, 'Invalid number'
|
||||||
|
|
||||||
# Validate count
|
# Validate count
|
||||||
if volumes and len(volumes) != fileCount:
|
if not volumes:
|
||||||
|
return None, 'No valid volume numbers parsed'
|
||||||
|
if len(volumes) != fileCount:
|
||||||
return None, f'Volume count ({len(volumes)}) ≠ file count ({fileCount})'
|
return None, f'Volume count ({len(volumes)}) ≠ file count ({fileCount})'
|
||||||
|
|
||||||
return volumes, None
|
return volumes, None
|
||||||
|
|||||||
Reference in New Issue
Block a user