There is a potential bug risk in the current map filename generation logic. The filename is derived directly from the destination string, which may contain special characters or result in duplicate filenames if the same destination is used multiple times. This can lead to filename collisions or invalid filenames, especially on filesystems with strict naming rules.
Suggested Solution:
- Sanitize the
destination string to remove or replace special characters.
- Add a hash of the destination to the filename to ensure uniqueness.
Example implementation:
import hashlib
import re
# Sanitize destination for filename
sanitized_destination = re.sub(r'[^a-zA-Z0-9_]', '_', destination.lower())
# Create a short hash of the destination for uniqueness
dest_hash = hashlib.md5(destination.encode('utf-8')).hexdigest()[:8]
map_filename = f"{sanitized_destination}_{dest_hash}_map.png"
map_path = self.maps_directory / map_filename
Action Items:
- Update the map filename generation logic to use the above approach or similar.
- Add tests to ensure filenames are unique and valid for various destination strings.
Note: This code path is currently not in active use and serves as an example, but it should be fixed before any production use.
I created this issue for @ItsSimko from #575 (comment).
Tips and commands
Getting Help
There is a potential bug risk in the current map filename generation logic. The filename is derived directly from the
destinationstring, which may contain special characters or result in duplicate filenames if the same destination is used multiple times. This can lead to filename collisions or invalid filenames, especially on filesystems with strict naming rules.Suggested Solution:
destinationstring to remove or replace special characters.Example implementation:
Action Items:
Note: This code path is currently not in active use and serves as an example, but it should be fixed before any production use.
I created this issue for @ItsSimko from #575 (comment).
Tips and commands
Getting Help