-
Notifications
You must be signed in to change notification settings - Fork 12
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
[DEV-19242] Feature - Sharing & Downloading #1212
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Skipped Deployments
|
59e3b0d
to
4a19da8
Compare
8587d87
to
7d63878
Compare
- Refactoring - Nice output formatting - Extracting unnecessary code to be lazy loaded / called as an server function in order to reduce page load time
const clonedElement = element.cloneNode(true) as HTMLElement; | ||
|
||
clonedElement.querySelectorAll('table').forEach((node) => { | ||
node.outerHTML = `<div>${htmlTableToPlainText(node)}</div>`; |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to ensure that any text content extracted from the DOM is properly escaped before being reinserted as HTML. This can be achieved by using a function that escapes HTML meta-characters, such as &
, <
, >
, "
, and '
. We will create a utility function to perform this escaping and use it in the htmlTableToPlainText
function.
- Create a utility function
escapeHtml
to escape HTML meta-characters. - Use the
escapeHtml
function to escape the content before inserting it into the<div>
element in thehtmlTableToPlainText
function.
-
Copy modified lines R5-R15 -
Copy modified line R60
@@ -4,2 +4,13 @@ | ||
|
||
function escapeHtml(text: string): string { | ||
const map: Record<string, string> = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''', | ||
}; | ||
return text.replace(/[&<>"']/g, function(m) { return map[m]; }); | ||
} | ||
|
||
type TagName = string; | ||
@@ -48,3 +59,3 @@ | ||
clonedElement.querySelectorAll('table').forEach((node) => { | ||
node.outerHTML = `<div>${htmlTableToPlainText(node)}</div>`; | ||
node.outerHTML = `<div>${escapeHtml(htmlTableToPlainText(node))}</div>`; | ||
}); |
No description provided.