Skip to content

Commit 7e5cdd5

Browse files
authored
Fix: path sanitizer and timestamp sorting errors
Fix: path sanitizer and timestamp sorting errors ( I encountered these errors issues with the script using Windows 11. Changing these two lines got the script to work for me. ) - Fixed a bug in Windows path sanitizer where String#gsub was incorrectly called with a Proc as the replacement. Replaced with block form to ensure proper character escaping for Windows-incompatible file path characters. - Fixed an ArgumentError in file sorting when a file snapshot’s timestamp was nil. Updated sort logic to safely handle nil timestamps by converting them to strings or integers, preventing comparison errors between NilClass and String/Integer. These changes prevent fatal runtime errors when downloading files with certain URLs or incomplete metadata, improving robustness for sites with inconsistent archive data.
1 parent 4160ff5 commit 7e5cdd5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/wayback_machine_downloader.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def get_file_list_by_timestamp
384384
end
385385
else
386386
file_list_curated = get_file_list_curated
387-
file_list_curated = file_list_curated.sort_by { |k,v| v[:timestamp] }.reverse
387+
file_list_curated = file_list_curated.sort_by { |_,v| v[:timestamp].to_s }.reverse
388388
file_list_curated.map do |file_remote_info|
389389
file_remote_info[1][:file_id] = file_remote_info[0]
390390
file_remote_info[1]
@@ -649,7 +649,7 @@ def download_file (file_remote_info, http)
649649
# for Windows, we need to sanitize path components to avoid invalid characters
650650
# this prevents issues with file names that contain characters not allowed in
651651
# Windows file systems. See # https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
652-
element.gsub(/[:\*?"<>\|\&\=\/\\]/, ->(match) { '%' + match.ord.to_s(16).upcase })
652+
element.gsub(/[:\*?"<>\|\&\=\/\\]/) { |match| '%' + match.ord.to_s(16).upcase }
653653
else
654654
element
655655
end

0 commit comments

Comments
 (0)