ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.75k stars 2.24k forks source link

[BUG]: The media file name with square brackets was not processed correctly #17456

Closed ChuckieChen945 closed 1 week ago

ChuckieChen945 commented 1 week ago

Checked for duplicates?

Does it also happen in the desktop version?

What are the steps to reproduce this bug?

  1. Reference some media files in the card template, with some filenames containing square brackets (not necessarily in pairs), as shown below:

    {{front}}</br>
    
    <img src="_heart[123].png">
    <img src="_heart[_test.png">
    <img src="_heart.png">
  2. Study a card using this template
  3. Media files with filenames containing square brackets fail to display properly

Image

Expected behaviour

Media files with filenames containing square brackets should be handled correctly, as they are in Anki Desktop:

Image

Debug info

AnkiDroid Version = 2.20alpha1 (edd1c61e6445ccac2ddf3cabe0d63c6a303f27b7)

Backend Version = 0.1.43-anki24.10rc2 (24.10rc2 898c91284bc97c928adbf1bcc8ca885b068dac5f)

Android Version = 10 (SDK 29)

ProductFlavor = full

Manufacturer = HUAWEI

Model = MXW-AN00

Hardware = mt6873

Webview User Agent = Mozilla/5.0 (Linux; Android 10; MXW-AN00 Build/HONORMXW-AN00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/99.0.4844.88 Mobile Safari/537.36

ACRA UUID = 415b3982-d60c-4528-9002-85dc99d4ac32

FSRS = 1.4.3 (Enabled: true)

Crash Reports Enabled = true

(Optional) Anything else you want to share?

No response

Research

BrayanDSO commented 1 week ago

Escape the brackets and it should work.

ChuckieChen945 commented 1 week ago

Thank you for your suggestion. I’ve tried the following code:

{{front}}</br>

<img src="_heart&#91;123&#93;.png">
<img src="_heart&#91;_test.png">
<img src="_heart.png">

and also:

{{front}}</br>

<img src="_heart\[123\].png">
<img src="_heart\[_test.png">
<img src="_heart.png">

However, escaping the brackets using &#91; and &#93; or \ did not resolve the issue. Neither the manual nor the FAQ provides a solution for this specific problem. Did I miss something? If so, could you please clarify further?

It’s worth noting that using square brackets ([ ]) in filenames works perfectly fine in Anki Desktop without any need for escaping. This inconsistency between AnkiDroid and Anki Desktop appears to be an Anki Ecosystem Compatibility issue.

I believe it would be ideal to align AnkiDroid's behavior with Anki Desktop to ensure a consistent user experience across platforms. Thank you for considering this, and please let me know if you need any additional information or testing!

lukstbit commented 1 week ago

@ChuckieChen945 I just tested this out of curiosity and it works. Did you try closing those img tags: <img src="_heart[123].png" /> ?

ChuckieChen945 commented 1 week ago

After further investigation, I discovered that media files containing square brackets cannot be synced via AnkiWeb. It appears that Anki does not support special characters, including square brackets, in media filenames.

When you add media to a field—either by using the paperclip icon in the editor or by pasting it into a field—Anki automatically handles special characters. However, referencing media files with special characters directly in templates may lead to issues.

Thank you again for your time and support in addressing this matter! I’m leaving this information here as a reference for others who may encounter similar problems.