diff --git a/src/pages/Details.vue b/src/pages/Details.vue index 17d32365c..f060dc81e 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -9,7 +9,7 @@
{{ monitor.id }}
-

{{ monitor.description }}

+

@@ -399,6 +399,19 @@ export default { screenshotURL() { return getResBaseURL() + this.monitor.screenshot + "?time=" + this.cacheTime; + }, + + processedDescription() { + if (!this.monitor.description) { + return ''; + } + + const urlPattern = /(\b(?:https?|ftp|file|smb|ssh|telnet|ldap|git):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi; + const processed = this.monitor.description.replace( + urlPattern, + url => `${this.escapeHtml(url)}` + ); + return processed; } }, @@ -656,6 +669,20 @@ export default { .replace("https://example.com/api/push/key?status=up&msg=OK&ping=", this.pushURL); this.pushMonitor.code = code; }); + }, + + /** + * Escape HTML + * @param {string} unsafe Unsafe string + * @returns {string} Safe string + */ + escapeHtml(unsafe) { + return unsafe + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); } }, };