Bug report - incorrect media referencing on 2nd paste

Hi, I just wanted to report a bug that I may have identified, and it sounds like others have been experiencing a similar issue.

Device info: Macbook M1

Anki: Version ⁨26.09.2

Date of onset: a 1-2 weeks ago?

Issue: incorrect media referencing in the CSS when you copy and paste the same image from outside of anki, a subsequent time into the same or a different card on the desktop app.

This seems to be specifically a case-sensitive change, where the name of the initial image from outside the media folder is capitalised (e.g. TEST.png), but pasting it into anki for the first time converts it into all lower case (and this is what is replicated in the code and in the media folder e.g. test.png).

However, a subsequent paste from the original file outside of the media folder or anki will retain the original case in the code (e.g. TEST.png) - and this causes the media to appear as referenced by cards, but “not found in the media folder” and as a “?” on an iphone/ipad, but not on desktop.

I was able to reproduce this behavior on Anki 26.09.3, macOS Golden Gate 27.0.1.

I think what might be happening during the second paste is that add_data_to_folder_uniquely() is checking the hash for a file named “TEST.png” to see if the file already exists in media.collection. However, on case insensitive filesystems, doing so results in a false positive if “test.png” was previously added (from the first paste). Because of the false positive, Anki believes that “TEST.png” exists in media.collection and adds “TEST.png” to the note field.

See also: Missing media on AnkiWeb after restoring files locally - #8 by BenJamesBen