Skip to content

(opds): remove redundant UTF-8 fixup#15122

Merged
Frenzie merged 1 commit into
koreader:masterfrom
D4n1984:opds_rename
Mar 17, 2026
Merged

(opds): remove redundant UTF-8 fixup#15122
Frenzie merged 1 commit into
koreader:masterfrom
D4n1984:opds_rename

Conversation

@D4n1984

@D4n1984 D4n1984 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

…names

The getLocalDownloadPath function was calling fixUtf8 with '_' replacement on the full path (directory + filename), after the filename had already been properly sanitized by getSafeFilename which calls fixUtf8 with ''.

This double processing with different replacement characters caused:

  • Non-UTF8 bytes (from URL decoding or header issues) to be replaced with '_'
  • Encoding artifacts like '=' characters combined with '_' replacements
  • File extensions corrupted (e.g., .cbz becomes .cbz_=)

The fix removes the redundant fixUtf8 call on the full path. The filename is already properly validated by getSafeFilename, and applying fixUtf8 again on the combined path is unnecessary and harmful.


This change is Reviewable

…names

The getLocalDownloadPath function was calling fixUtf8 with '_' replacement
on the full path (directory + filename), after the filename had already been
properly sanitized by getSafeFilename which calls fixUtf8 with ''.

This double processing with different replacement characters caused:
- Non-UTF8 bytes (from URL decoding or header issues) to be replaced with '_'
- Encoding artifacts like '=' characters combined with '_' replacements
- File extensions corrupted (e.g., .cbz becomes .cbz_=)

The fix removes the redundant fixUtf8 call on the full path. The filename
is already properly validated by getSafeFilename, and applying fixUtf8
again on the combined path is unnecessary and harmful.
@Frenzie

Frenzie commented Mar 17, 2026

Copy link
Copy Markdown
Member

While it does indeed look like a now redundant leftover, are these symptoms you mention something you've actually seen or were they made up by AI? Because if invalid UTF-8 was already replaced with an empty string, running it again shouldn't do anything other than waste some small amount of CPU cycles.

@D4n1984

D4n1984 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

This is the behavior I am currently experiencing on my device (Boox Note Air5C).
When I download files via OPDS(Komga Server Selfhosted), hyphens are added to the file name. This would not be a major issue if it did not also modify the file extension. An original .cbz extension ends up being converted into .cbz-, and since that extension is not recognized, an error occurs when trying to open the file.

I reviewed the code to see where this could be coming from, and I only found that the file name is modified at that point. Even so, I also reviewed it with Copilot, which confirmed that the name is only modified there and that this logic is redundant.

Unfortunately, I have not been able to test the .apk, as I do not have the ability to compile it, but I still went ahead and created the PR, since in principle it should not affect any other logic or functionality, and at worst it would simply result in a more optimized implementation.

@D4n1984

D4n1984 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

To add more info:

Expected behavior

The downloaded file should preserve its original name and extension:

Cap 1 - The first book.cbz

Actual behavior

The file name is modified during download, resulting in an encoded and altered name and extension:

=UTF8_Q_Cap-1-The_first_book.cbz=

I’m not sure why additional characters are being added.

@Frenzie Frenzie changed the title fix(opds): remove redundant UTF-8 fixup that corrupts downloaded file… (opds): remove redundant UTF-8 fixup Mar 17, 2026
@Frenzie

Frenzie commented Mar 17, 2026

Copy link
Copy Markdown
Member

I'll merge it because it is indeed redundant, but this won't solve your problem.

@Frenzie Frenzie merged commit 825b9bc into koreader:master Mar 17, 2026
4 checks passed
@Frenzie Frenzie added this to the 2026.02 milestone Mar 17, 2026
@Frenzie

Frenzie commented Mar 17, 2026

Copy link
Copy Markdown
Member

Is that on the old stable (new one likely coming today, depending on how busy I am tonight) or the current nightly? There have been some related changes like #14732.

@Frenzie Frenzie added the OPDS label Mar 17, 2026
jqs7 pushed a commit to jqs7/koreader that referenced this pull request Mar 19, 2026
The filename is already sanitized by util.getSafeFilename(), which calls util.fixUtf8() internally.
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
The filename is already sanitized by util.getSafeFilename(), which calls util.fixUtf8() internally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants