Skip to content

Commit 644e1e0

Browse files
Updated the characters AppleNote.title_as_filename strips out to be nice to Windows filesystems.
1 parent f3e4e25 commit 644e1e0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/AppleNote.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ def unique_id(use_uuid)
433433

434434
##
435435
# Generate a file name for exporting this note to an HTML file
436-
def title_as_filename(ext = '', use_uuid: false)
437-
file_title = title ? title.tr('/:', '_') : "Untitled"
436+
def title_as_filename(ext = '', use_uuid = false)
437+
file_title = title ? title.tr('[\\/*"<>?|:]\'', '_') : "Untitled"
438438
"#{unique_id(use_uuid)} - #{file_title}#{ext}"
439439
end
440440

spec/base_classes/apple_note.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,22 @@
510510
tmp_note.add_cloudkit_server_record_data(binary_plist)
511511
expect(tmp_note.generate_html.text).to include("CloudKit Last Modified Device: Tester’s iPhone")
512512
end
513+
514+
it "removes troublesome characters when using the title as a filename" do
515+
bad_title = AppleNote.new(3,
516+
22,
517+
"Busted[Title], Do not use?\'\/*<>?|:\'",
518+
File.read(TEST_BLOB_DATA_DIR + "simple_note_protobuf_gzipped.bin"),
519+
608413790,
520+
608413790,
521+
tmp_account,
522+
tmp_folder)
523+
bad_title.uuid = note_uuid
524+
expect(bad_title.title_as_filename('', false)).to eq "#{bad_title.note_id} - Busted_Title_, Do not use__________"
525+
expect(bad_title.title_as_filename('.html', false)).to eq "#{bad_title.note_id} - Busted_Title_, Do not use__________.html"
526+
expect(bad_title.title_as_filename('', true)).to eq "#{note_uuid} - Busted_Title_, Do not use__________"
527+
expect(bad_title.title_as_filename('.html', true)).to eq "#{note_uuid} - Busted_Title_, Do not use__________.html"
528+
end
513529
end
514530

515531
end

0 commit comments

Comments
 (0)