commit 96907538b0ecdb9c23ec6dc73dfda9ff0f5538d6
parent 79a417cab8d18ea80a77dbe949563afcb486e40d
Author: Dan Callaghan <djc@djc.id.au>
Date: Fri, 20 Nov 2026 19:59:27 +1100
strip out slashes in attachment filenames when saving to dir
Commit 2caccbb02f did this already for the default suggested filename,
and when saving all attachments to disk, but missed the case where the
user chooses a specific attachment and then gives a directory to save
into.
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/sup/modes/thread_view_mode.rb b/lib/sup/modes/thread_view_mode.rb
@@ -397,7 +397,7 @@ EOS
# if user selects directory use file name from message
if fn and File.directory? fn
- fn = File.join(fn, chunk.filename)
+ fn = File.join(fn, chunk.filesafe_filename)
end
save_to_file(fn) { |f| f.print chunk.raw_content } if fn
diff --git a/test/unit/test_thread_view_mode.rb b/test/unit/test_thread_view_mode.rb
@@ -68,6 +68,18 @@ class TestThreadViewMode < Minitest::Test
expected_path = File.join destdir, "sup_.travis.yml"
assert File.exist? expected_path
assert_equal 260, File.size(expected_path)
+
+ ## Scroll to the attachment and save it to a directory.
+ destdir = File.join(@path, "saved2")
+ Dir.mkdir destdir
+ stub(BufferManager.instance).ask(:filename, "Save attachment to file or directory: ", "#{ENV["HOME"]}/sup_.travis.yml") { destdir }
+ stub(BufferManager.instance).flash("Successfully wrote #{destdir}/sup_.travis.yml.")
+ assert_equal "x Attachment: sup/.travis.yml (text/x-yaml; 260B)", mode[10][0][1]
+ mode.send :set_cursor_pos, 10
+ mode.save_to_disk
+ expected_path = File.join destdir, "sup_.travis.yml"
+ assert File.exist? expected_path
+ assert_equal 260, File.size(expected_path)
end
end