@@ -46,6 +46,19 @@ describe('OrgFile', function()
46
46
file :reload_sync ()
47
47
assert .are .same (4 , file .metadata .changedtick )
48
48
end )
49
+
50
+ it (' should load files with special characters in filename from buffer' , function ()
51
+ local special_filename = vim .fn .tempname () .. ' [test].org'
52
+ local file = load_file_sync ({ ' * Headline with bracket filename' }, special_filename )
53
+ vim .cmd (' edit ' .. vim .fn .fnameescape (file .filename ))
54
+
55
+ -- Test that OrgFile.load can find the buffer correctly
56
+ local loaded_file = OrgFile .load (special_filename ):wait ()
57
+ assert .are .same (special_filename , loaded_file .filename )
58
+ assert .are .same ({ ' * Headline with bracket filename' }, loaded_file .lines )
59
+
60
+ vim .cmd (' bdelete' )
61
+ end )
49
62
end )
50
63
51
64
describe (' reload' , function ()
@@ -564,6 +577,42 @@ describe('OrgFile', function()
564
577
assert .are .same (- 1 , file :bufnr ())
565
578
assert .is .True (vim .fn .bufnr (file .filename ) > 0 )
566
579
end )
580
+
581
+ it (' should work with filenames containing special characters' , function ()
582
+ -- Test various special characters that have regex meaning
583
+ local test_cases = {
584
+ ' [test].org' ,
585
+ ' (test).org' ,
586
+ ' test[1].org' ,
587
+ ' file.with.dots.org' ,
588
+ ' file+plus.org' ,
589
+ ' file*star.org' ,
590
+ ' file?question.org' ,
591
+ ' file$dollar.org' ,
592
+ ' file^caret.org' ,
593
+ }
594
+
595
+ for _ , special_filename in ipairs (test_cases ) do
596
+ local full_filename = vim .fn .tempname () .. special_filename
597
+ local file = load_file_sync ({
598
+ ' * Headline with special filename' ,
599
+ ' Content in special file' ,
600
+ }, full_filename )
601
+
602
+ -- Test that bufnr() works correctly
603
+ assert .are .same (- 1 , file :bufnr ())
604
+
605
+ -- Test that loading the buffer works
606
+ vim .cmd (' edit ' .. vim .fn .fnameescape (file .filename ))
607
+ assert .is .True (file :bufnr () > 0 , ' Failed for filename: ' .. special_filename )
608
+
609
+ -- Test that get_valid_bufnr() works
610
+ local bufnr = file :get_valid_bufnr ()
611
+ assert .is .True (bufnr > 0 , ' get_valid_bufnr failed for filename: ' .. special_filename )
612
+
613
+ vim .cmd (' bdelete' )
614
+ end
615
+ end )
567
616
end )
568
617
569
618
describe (' get_filetags' , function ()
0 commit comments