@@ -126,6 +126,41 @@ def test_noindexlanguage(tmp_path):
126126 assert not reader .has_fulltext_index
127127
128128
129+ def test_duplicatefiles (tmp_path , png_image , html_file ):
130+ fpath = tmp_path / "test.zim"
131+
132+ with open (png_image , "rb" ) as fh :
133+ png_data = fh .read ()
134+
135+ with Creator (fpath , "welcome" , "" ) as creator :
136+ creator .add_autodedup_filter (r"^images/.*$" )
137+ # add a file not matching filter patterns
138+ creator .add_item_for ("other_folder1/yahoo0.png" , "Image1" , fpath = png_image )
139+ # add same file but first matching filter patterns => will be added as-is
140+ creator .add_item_for ("images/yahoo1.png" , "Image1" , fpath = png_image )
141+ # add same file but second matching filter patterns
142+ # => will be replaced by a redirect
143+ creator .add_item_for ("images/yahoo2.png" , "Image2" , fpath = png_image )
144+ # add same file but not matching filter patterns => will be added as-is
145+ creator .add_item_for ("other_folder2/yahoo3.png" , "Image1" , fpath = png_image )
146+ # add same file matching filter patterns but with content instead of fpath
147+ # => will be replaced by a redirect
148+ creator .add_item_for ("images/yahoo4.png" , "Image3" , content = png_data )
149+
150+ reader = Archive (fpath )
151+ # make sure we have our image
152+ assert reader .get_item ("images/yahoo1.png" )
153+ assert not reader .get_entry_by_path ("images/yahoo1.png" ).is_redirect
154+ assert reader .get_item ("images/yahoo2.png" )
155+ assert reader .get_entry_by_path ("images/yahoo2.png" ).is_redirect
156+ assert reader .get_item ("images/yahoo4.png" )
157+ assert reader .get_entry_by_path ("images/yahoo4.png" ).is_redirect
158+ assert reader .get_item ("other_folder1/yahoo0.png" )
159+ assert not reader .get_entry_by_path ("other_folder1/yahoo0.png" ).is_redirect
160+ assert reader .get_item ("other_folder2/yahoo3.png" )
161+ assert not reader .get_entry_by_path ("other_folder2/yahoo3.png" ).is_redirect
162+
163+
129164def test_add_item_for (tmp_path ):
130165 fpath = tmp_path / "test.zim"
131166 # test without mimetype
0 commit comments