Skip to content

Commit

Permalink
fix: Internal links and TOC links not working when the document URL h…
Browse files Browse the repository at this point in the history
…as %-encoded characters

Fixes #662
  • Loading branch information
MurakamiShinyu committed Sep 30, 2020
1 parent 47ad0a1 commit bdabb71
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/vivliostyle/counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CounterListener implements CssCascade.CounterListener {
*/
countersOfId(id: string, counters: CssCascade.CounterValues) {
id = this.counterStore.documentURLTransformer.transformFragment(
encodeURIComponent(id),
id,
this.baseURL,
);
this.counterStore.countersById[id] = counters;
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/vivliostyle/epub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,7 @@ export class OPFDoc {
*/
transformFragment(fragment: string, baseURL: string): string {
const url = baseURL + (fragment ? `#${fragment}` : "");
return (
transformedIdPrefix + Base.escapeNameStrToHex(decodeURI(url), ":")
);
return transformedIdPrefix + Base.escapeNameStrToHex(url, ":");
}

/**
Expand All @@ -803,7 +801,7 @@ export class OPFDoc {
const r = url.match(/^([^#]*)#?(.*)$/);
if (r) {
const path = r[1] || baseURL;
const fragment = r[2];
const fragment = decodeURIComponent(r[2]);
if (path) {
if (self.items.some((item) => item.src === path)) {
return `#${this.transformFragment(fragment, path)}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/vivliostyle/vgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ export class ViewFactory
// (only first time).
if (firstTime) {
attributeValue = this.documentURLTransformer.transformFragment(
encodeURIComponent(attributeValue),
attributeValue,
this.xmldoc.url,
);
result.setAttribute(attributeName, attributeValue);
Expand Down

1 comment on commit bdabb71

@vercel
Copy link

@vercel vercel bot commented on bdabb71 Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.