1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-02 14:49:16 +02:00

Update replacements.js-substitute

about function substitute
when (content.opf > manifest > item > href) is an encode-uri: '%E4%B8%AD%E6%96%87'

but the content's source is not:
'中文'

need decode

to substitute blob successfully
This commit is contained in:
cat-orange 2024-07-26 16:32:41 +08:00 committed by GitHub
parent f09089cf77
commit 51e3f768f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -128,6 +128,13 @@ export function replaceLinks(contents, fn) {
export function substitute(content, urls, replacements) { export function substitute(content, urls, replacements) {
urls.forEach(function(url, i){ urls.forEach(function(url, i){
if (url && replacements[i]) { if (url && replacements[i]) {
// when (content.opf > manifest > item > href) is a encodeURI, but the content's source is not
try {
let decodeUri = window.decodeURIComponent(url);
content = content.replace(new RegExp(decodeUri, "g"), replacements[i]);
} catch (err) {
throw err
}
// Account for special characters in the file name. // Account for special characters in the file name.
// See https://stackoverflow.com/a/6318729. // See https://stackoverflow.com/a/6318729.
url = url.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); url = url.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");