## Summary * **What is the goal of this PR?** * Fix EPUBs where internal file references are written in URL-style escaped form, like spaces appearing as `%20`, so the reader can find the right files instead of treating those references as missing. * **What changes are included?** * Added a small shared helper that converts those escaped EPUB-internal paths back into their normal filenames before we try to look them up. * Applied that cleanup step across the EPUB parsing flow wherever we resolve internal references, including cover images, manifest items, TOC links, spine entries, and inline HTML images. * Kept the change narrowly focused on EPUB-internal asset resolution rather than changing broader URL or networking behavior. ## Additional Context * The user-facing bug here is that some books package their internal filenames in an escaped form, so a file like `Chapter 1.xhtml` may be referenced more like `Chapter%201.xhtml`. The reader was treating that escaped text as the literal filename, which means otherwise-valid books could lose images, covers, or chapter targets because the lookup no longer matched the real file inside the EPUB. * Risk is intentionally low. The helper only rewrites valid `%XX` escape sequences and leaves malformed input alone, so it should improve compatibility with escaped filenames without broadening the parser’s behavior in unrelated cases. ## Local Testing Performed * This was tested on my device with the user-provided optimized epub that was not rendering images within the text prior to this fix (cover image and chapter headers were rendering fine): [orv_main_baseline.epub.zip](https://github.com/user-attachments/files/28529545/orv_main_baseline.epub.zip) * This was also tested by the user with a local build and the affected epub and confirmed to be working ## Steps for Testing * Try to open the affected epub (linked above) or any epub that has similar percent-encoding on a build prior to this fix. * Apply this fix, clear book cache, and re-open the affected book. * Images should render properly. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< YES >**_
77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
#pragma once
|
|
#include <WString.h>
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace FsHelpers {
|
|
|
|
std::string decodeUriEscapes(const std::string& path);
|
|
|
|
std::string normalisePath(const std::string& path);
|
|
|
|
void sortFileList(std::vector<std::string>& strs);
|
|
|
|
/**
|
|
* Check if the given filename ends with the specified extension (case-insensitive).
|
|
*/
|
|
bool checkFileExtension(std::string_view fileName, const char* extension);
|
|
inline bool checkFileExtension(const String& fileName, const char* extension) {
|
|
return checkFileExtension(std::string_view{fileName.c_str(), fileName.length()}, extension);
|
|
}
|
|
|
|
// Check for either .jpg or .jpeg extension (case-insensitive)
|
|
bool hasJpgExtension(std::string_view fileName);
|
|
inline bool hasJpgExtension(const String& fileName) {
|
|
return hasJpgExtension(std::string_view{fileName.c_str(), fileName.length()});
|
|
}
|
|
|
|
// Check for .png extension (case-insensitive)
|
|
bool hasPngExtension(std::string_view fileName);
|
|
inline bool hasPngExtension(const String& fileName) {
|
|
return hasPngExtension(std::string_view{fileName.c_str(), fileName.length()});
|
|
}
|
|
|
|
// Check for .bmp extension (case-insensitive)
|
|
bool hasBmpExtension(std::string_view fileName);
|
|
|
|
// Check for .gif extension (case-insensitive)
|
|
bool hasGifExtension(std::string_view fileName);
|
|
inline bool hasGifExtension(const String& fileName) {
|
|
return hasGifExtension(std::string_view{fileName.c_str(), fileName.length()});
|
|
}
|
|
|
|
// Check for .epub extension (case-insensitive)
|
|
bool hasEpubExtension(std::string_view fileName);
|
|
inline bool hasEpubExtension(const String& fileName) {
|
|
return hasEpubExtension(std::string_view{fileName.c_str(), fileName.length()});
|
|
}
|
|
|
|
// Check for either .xtc or .xtch extension (case-insensitive)
|
|
bool hasXtcExtension(std::string_view fileName);
|
|
|
|
// Check for .txt extension (case-insensitive)
|
|
bool hasTxtExtension(std::string_view fileName);
|
|
inline bool hasTxtExtension(const String& fileName) {
|
|
return hasTxtExtension(std::string_view{fileName.c_str(), fileName.length()});
|
|
}
|
|
|
|
// Check for .md extension (case-insensitive)
|
|
bool hasMarkdownExtension(std::string_view fileName);
|
|
|
|
// Check for .css extension (case-insensitive)
|
|
bool hasCssExtension(std::string_view fileName);
|
|
inline bool hasCssExtension(const String& fileName) {
|
|
return hasCssExtension(std::string_view{fileName.c_str(), fileName.length()});
|
|
}
|
|
std::string extractFolderPath(const std::string& filePath);
|
|
|
|
/**
|
|
* Sanitize a filename/path component for FAT32 in a caller-provided buffer.
|
|
* Replaces invalid path characters, spaces, and control characters with '-'.
|
|
*/
|
|
void sanitizePathComponentForFat32(const char* input, char* output, size_t maxLen);
|
|
|
|
} // namespace FsHelpers
|