Skip to content

Commit 2066902

Browse files
committed
add url decoding and html escaping
1 parent c377e99 commit 2066902

File tree

1 file changed

+7
-0
lines changed
  • src/main/resources/embedding/assets

1 file changed

+7
-0
lines changed

src/main/resources/embedding/assets/entry.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ $(function(){
5757
return xmlHttp.responseText;
5858
}
5959

60+
function escapeHtml(text) {
61+
return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
62+
}
63+
6064
function convertLinks(){
6165
const elements = $('.markdown-body p');
6266
let element;
@@ -80,9 +84,12 @@ $(function(){
8084
}
8185
let commitUrl = getCommitUrl(url, filepath);
8286
try{
87+
filepath = decodeURIComponent(filepath);
88+
filepath = escapeHtml(filepath);
8389
let content = getContent(url);
8490
let linesAll = content.split(/\n|\r\n?/);
8591
let lines = linesAll.slice(startLine-1, endLine).join("\n");
92+
lines = escapeHtml(lines);
8693
let snippetElement = generateSnippetElement(repo, filepath, commit, startLine, endLine, lines, url, commitUrl);
8794
element.insertAdjacentHTML('afterend', snippetElement);
8895
element.remove();

0 commit comments

Comments
 (0)