Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update replacements.js about function substitute #1393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/utils/replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ export function replaceLinks(contents, fn) {
export function substitute(content, urls, replacements) {
urls.forEach(function(url, 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.
// See https://stackoverflow.com/a/6318729.
url = url.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
Expand Down