diff --git a/src/mastodon-timeline.js b/src/mastodon-timeline.js
index 17b6020..393b298 100644
--- a/src/mastodon-timeline.js
+++ b/src/mastodon-timeline.js
@@ -155,9 +155,9 @@ MastodonApi.prototype.buildTimeline = async function () {
if (this.LINK_SEE_MORE) {
let linkSeeMorePath = "";
if (this.TIMELINE_TYPE === "profile") {
- linkSeeMorePath = this.PROFILE_NAME;
+ linkSeeMorePath = encodeURIComponent(this.PROFILE_NAME);
} else if (this.TIMELINE_TYPE === "hashtag") {
- linkSeeMorePath = "tags/" + this.HASHTAG_NAME;
+ linkSeeMorePath = "tags/" + encodeURIComponent(this.HASHTAG_NAME);
} else if (this.TIMELINE_TYPE === "local") {
linkSeeMorePath = "public/local";
}
@@ -218,7 +218,7 @@ MastodonApi.prototype.buildTimeline = async function () {
e.target.parentNode.className !== "mt-toot-preview-image" &&
urlToot
) {
- window.open(urlToot, "_blank");
+ window.open(urlToot, "_blank", "noopener");
}
};
@@ -324,7 +324,7 @@ MastodonApi.prototype.getTimelineData = async function () {
reject(new Error("Something went wrong fetching data"));
this.mtBodyContainer.innerHTML =
'
❌Sorry, request failed:' +
- error.message +
+ this.escapeHtml(error.message) +
"
";
this.mtBodyContainer.setAttribute("role", "none");
return { [key]: [] };
@@ -375,14 +375,14 @@ MastodonApi.prototype.assambleToot = function (c, i) {
'
' +
"" +
'' +
'

' +
"
" +
"" +
@@ -390,9 +390,9 @@ MastodonApi.prototype.assambleToot = function (c, i) {
// User name and url
userName = this.showEmojos(
- c.reblog.account.display_name
+ this.escapeHtml(c.reblog.account.display_name
? c.reblog.account.display_name
- : c.reblog.account.username,
+ : c.reblog.account.username),
this.FETCHED_DATA.emojos
);
user =
@@ -422,7 +422,7 @@ MastodonApi.prototype.assambleToot = function (c, i) {
'
' +
"" +
"" +
@@ -430,7 +430,7 @@ MastodonApi.prototype.assambleToot = function (c, i) {
// User name and url
userName = this.showEmojos(
- c.account.display_name ? c.account.display_name : c.account.username,
+ this.escapeHtml(c.account.display_name ? c.account.display_name : c.account.username),
this.FETCHED_DATA.emojos
);
user =
@@ -438,7 +438,7 @@ MastodonApi.prototype.assambleToot = function (c, i) {
'' +
- userName +
+ this.escapeHtml(userName) +
' account' +
"" +
"";
@@ -720,7 +720,7 @@ MastodonApi.prototype.placeMedias = function (m, s) {
'
' +
"";
@@ -743,14 +743,14 @@ MastodonApi.prototype.placePreviewLink = function (c) {
'">
'
: '📄
') +
"" +
'' +
(c.provider_name
? '' +
- this.parseHTMLstring(c.provider_name) +
+ this.escapeHtml(this.parseHTMLstring(c.provider_name)) +
""
: "") +
'' +
@@ -758,7 +758,7 @@ MastodonApi.prototype.placePreviewLink = function (c) {
"" +
(c.author_name
? '' +
- this.parseHTMLstring(c.author_name) +
+ this.escapeHtml(this.parseHTMLstring(c.author_name)) +
""
: "") +
"
" +
@@ -812,12 +812,14 @@ MastodonApi.prototype.parseHTMLstring = function (s) {
};
/**
- * Replace quotes
+ * Escape quotes and other special characters, to make them safe to add
+ * to HTML content and attributes as plain text
* @param {string} s String
* @returns {string} String
*/
-MastodonApi.prototype.replaceQuotes = function (s) {
- return s.replace('"', "'");
+MastodonApi.prototype.escapeHtml = function (s) {
+ return (s ?? "").replace("&", "&").replace("<", "<")
+ .replace(">", ">").replace('"', """);
};
/**