Skip to content

Commit 94fa52b

Browse files
micmrotobli
authored andcommitted
#149 escape html characters of raw-content (#152)
1 parent 76d954c commit 94fa52b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/ts/waterfall/details-overlay/html-details-body.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {WaterfallEntry} from "../../typing/waterfall";
2-
import {getKeys, KvTuple} from "./extract-details-keys";
1+
import { WaterfallEntry } from "../../typing/waterfall";
2+
import { getKeys, KvTuple } from "./extract-details-keys";
33

44
function makeDefinitionList(dlKeyValues: KvTuple[], addClass: boolean = false) {
55
let makeClass = (key: string) => {
@@ -76,6 +76,15 @@ function makeTabBtn(name: string, tab: string) {
7676
return !!tab ? `<li><button class="tab-button">${name}</button></li>` : "";
7777
}
7878

79+
function escapeHtml(unsafe) {
80+
return unsafe
81+
.replace(/&/g, "&amp;")
82+
.replace(/</g, "&lt;")
83+
.replace(/>/g, "&gt;")
84+
.replace(/"/g, "&quot;")
85+
.replace(/'/g, "&#039;");
86+
}
87+
7988
export function createDetailsBody(requestID: number, entry: WaterfallEntry, accordeonHeight: number) {
8089

8190
let html = document.createElement("html") as HTMLHtmlElement;
@@ -129,7 +138,7 @@ export function createDetailsBody(requestID: number, entry: WaterfallEntry, acco
129138
</div>
130139
${timingsTab}
131140
<div class="tab raw-data">
132-
<pre><code>${JSON.stringify(entry.rawResource, null, 2)}</code></pre>
141+
<pre><code>${escapeHtml(JSON.stringify(entry.rawResource, null, 2))}</code></pre>
133142
</div>
134143
${imgTab}
135144
</div>

0 commit comments

Comments
 (0)