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: remove unnecessarry escaping #752

Merged
merged 1 commit into from
May 21, 2024
Merged
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
24 changes: 1 addition & 23 deletions src/app/markdown/renderer/marktone-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ import KintoneClient from "../../kintone/kintone-client";
import { highlightStyles, languageAliases } from "./highlight-settings";

class MarktoneRendererHelper {
static escapeHTML(html: string): string {
const escapeTest = /[&<>"']/;
const escapeReplace = new RegExp(escapeTest, "g");
const replacements: { [key: string]: string } = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;",
};

if (escapeTest.test(html)) {
return html.replace(escapeReplace, (ch) => replacements[ch]);
}

return html;
}

static unescapeHTML(html: string): string {
const unescapeTest = /(&(?:lt|amp|gt|quot|#39);)/;
const unescapeReplace = new RegExp(unescapeTest, "g");
Expand Down Expand Up @@ -206,8 +188,6 @@ class MarktoneRenderer extends Renderer {
}

link(href: string, title: string, text: string): string {
// For later sanitization with DOMPurify, skip the `href` sanitization here.

if (href === null) return text;

if (href.startsWith("tmp:")) {
Expand All @@ -232,7 +212,7 @@ class MarktoneRenderer extends Renderer {
}

const attributes: { [key: string]: string } = {
href: MarktoneRendererHelper.escapeHTML(href),
href,
};
if (title) attributes.title = title;

Expand All @@ -243,8 +223,6 @@ class MarktoneRenderer extends Renderer {
}

image(href: string, title: string | null, text: string): string {
// For later sanitization with DOMPurify, skip the `href` sanitization here.

if (href === null) {
return text;
}
Expand Down