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

Fix broken Markdown headings with quotes #1513

Merged
merged 8 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/common-elements/linkify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function navigate(history: HistoryService, event: React.MouseEvent<HTMLAnchorEle
!isModifiedEvent(event) // ignore clicks with modifier keys
) {
event.preventDefault();
history.replace(to);
history.replace(encodeURI(to));
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/services/MenuStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class MenuStore {
if (!id) {
return;
}
scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${id}"]`);
scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(id)}"]`);
}

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ export class MenuStore {
item = this.flatItems.find(i => SECURITY_SCHEMES_SECTION_PREFIX.startsWith(i.id));
this.activateAndScroll(item, false);
}
this.scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${id}"]`);
this.scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(id)}"]`);
}
};

Expand All @@ -163,7 +163,7 @@ export class MenuStore {
*/
getElementAt(idx: number): Element | null {
const item = this.flatItems[idx];
return (item && querySelector(`[${SECTION_ATTR}="${item.id}"]`)) || null;
return (item && querySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(item.id)}"]`)) || null;
}

/**
Expand All @@ -175,7 +175,7 @@ export class MenuStore {
if (item && item.type === 'group') {
item = item.items[0];
}
return (item && querySelector(`[${SECTION_ATTR}="${item.id}"]`)) || null;
return (item && querySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(item.id)}"]`)) || null;
}

/**
Expand Down Expand Up @@ -224,7 +224,7 @@ export class MenuStore {

this.activeItemIdx = item.absoluteIdx!;
if (updateLocation) {
this.history.replace(item.id, rewriteHistory);
this.history.replace(encodeURI(item.id), rewriteHistory);
}

item.activate();
Expand Down Expand Up @@ -276,4 +276,12 @@ export class MenuStore {
this._unsubscribe();
this._hashUnsubscribe();
}

private static escapeQuotes(str: string) : string {
if (typeof str != 'undefined') {
str = str.replace(/["\\]/g, '\\$&');
}

return str;
}
anastasiia-developer marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 2 additions & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,6 @@ function parseURL(url: string) {
export function unescapeHTMLChars(str: string): string {
return str
.replace(/&#(\d+);/g, (_m, code) => String.fromCharCode(parseInt(code, 10)))
.replace(/&amp;/g, '&');
.replace(/&amp;/g, '&')
.replace(/&quot;/g, '"');
}