-
Notifications
You must be signed in to change notification settings - Fork 5
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
Update documentation #250
Update documentation #250
Conversation
$el.each(function(i) { | ||
var title = $(this).attr('title'); | ||
if (title) { | ||
$insert.append("<li class=\"tab\"><a href=\"#\">" + title + "</a></li>"); |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium documentation
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 22 days ago
To fix the problem, we need to ensure that the title
attribute is properly escaped before being inserted into the HTML string. This can be done using a utility function that escapes special HTML characters. We will create a function to escape the title
attribute and use it in the listLanguages
function.
-
Copy modified lines R111-R121 -
Copy modified line R126
@@ -110,2 +110,13 @@ | ||
|
||
function escapeHtml(text) { | ||
var map = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''' | ||
}; | ||
return text.replace(/[&<>"']/g, function(m) { return map[m]; }); | ||
} | ||
|
||
function listLanguages($el, $insert) { | ||
@@ -114,3 +125,3 @@ | ||
if (title) { | ||
$insert.append("<li class=\"tab\"><a href=\"#\">" + title + "</a></li>"); | ||
$insert.append("<li class=\"tab\"><a href=\"#\">" + escapeHtml(title) + "</a></li>"); | ||
} |
$el.each(function(i) { | ||
var title = $(this).attr('title'); | ||
if (title) { | ||
$insert.append("<li class=\"tab\"><a href=\"#\">" + title + "</a></li>"); |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium documentation
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 22 days ago
To fix the problem, we need to ensure that the title
attribute is properly escaped before being inserted into the HTML. This can be achieved by using a function that escapes special HTML characters, preventing any potential XSS attacks.
The best way to fix this without changing existing functionality is to create a utility function that escapes HTML characters and use it to sanitize the title
attribute before concatenating it into the HTML string.
-
Copy modified lines R111-R125 -
Copy modified line R130
@@ -110,2 +110,17 @@ | ||
|
||
function escapeHtml(text) { | ||
return text.replace(/[&<>"'`=\/]/g, function (s) { | ||
return ({ | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''', | ||
'/': '/', | ||
'`': '`', | ||
'=': '=' | ||
})[s]; | ||
}); | ||
} | ||
|
||
function listLanguages($el, $insert) { | ||
@@ -114,3 +129,3 @@ | ||
if (title) { | ||
$insert.append("<li class=\"tab\"><a href=\"#\">" + title + "</a></li>"); | ||
$insert.append("<li class=\"tab\"><a href=\"#\">" + escapeHtml(title) + "</a></li>"); | ||
} |
No description provided.