mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-22 03:25:56 +00:00
Pass description through sanitize(marked())
This commit is contained in:
parent
1d60e6e57f
commit
5df79d0129
2 changed files with 13 additions and 71 deletions
|
@ -1,65 +0,0 @@
|
||||||
<template>
|
|
||||||
<span>
|
|
||||||
<template v-for="(part, index) in parts" :key="index">
|
|
||||||
<a
|
|
||||||
v-if="part.type === 'link'"
|
|
||||||
:href="part.content"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>{{ part.content }}</a>
|
|
||||||
<span v-else>{{ part.content }}</span>
|
|
||||||
</template>
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: "SafeLinks",
|
|
||||||
props: {
|
|
||||||
text: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
parts() {
|
|
||||||
if (!this.text) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlPattern = /(\b(?:https?|ftp|file|smb|ssh|telnet|ldap|git):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
|
|
||||||
const parts = [];
|
|
||||||
let lastIndex = 0;
|
|
||||||
|
|
||||||
this.text.replace(urlPattern, (match, url, offset) => {
|
|
||||||
// Add text before the link
|
|
||||||
if (offset > lastIndex) {
|
|
||||||
parts.push({
|
|
||||||
type: "text",
|
|
||||||
content: this.text.slice(lastIndex, offset)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the link
|
|
||||||
parts.push({
|
|
||||||
type: "link",
|
|
||||||
content: url
|
|
||||||
});
|
|
||||||
|
|
||||||
lastIndex = offset + match.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add remaining text after last link
|
|
||||||
if (lastIndex < this.text.length) {
|
|
||||||
parts.push({
|
|
||||||
type: "text",
|
|
||||||
content: this.text.slice(lastIndex)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
|
@ -9,9 +9,8 @@
|
||||||
<div>{{ monitor.id }}</div>
|
<div>{{ monitor.id }}</div>
|
||||||
</div>
|
</div>
|
||||||
</h1>
|
</h1>
|
||||||
<p v-if="monitor.description">
|
<!-- eslint-disable-next-line vue/no-v-html-->
|
||||||
<SafeLinks :text="monitor.description" />
|
<p v-if="monitor.description" v-html="descriptionHTML"></p>
|
||||||
</p>
|
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<div class="tags">
|
<div class="tags">
|
||||||
<Tag v-for="tag in monitor.tags" :key="tag.id" :item="tag" :size="'sm'" />
|
<Tag v-for="tag in monitor.tags" :key="tag.id" :item="tag" :size="'sm'" />
|
||||||
|
@ -281,13 +280,14 @@ import Status from "../components/Status.vue";
|
||||||
import Datetime from "../components/Datetime.vue";
|
import Datetime from "../components/Datetime.vue";
|
||||||
import CountUp from "../components/CountUp.vue";
|
import CountUp from "../components/CountUp.vue";
|
||||||
import Uptime from "../components/Uptime.vue";
|
import Uptime from "../components/Uptime.vue";
|
||||||
import SafeLinks from "../components/SafeLinks.vue";
|
|
||||||
import Pagination from "v-pagination-3";
|
import Pagination from "v-pagination-3";
|
||||||
const PingChart = defineAsyncComponent(() => import("../components/PingChart.vue"));
|
const PingChart = defineAsyncComponent(() => import("../components/PingChart.vue"));
|
||||||
import Tag from "../components/Tag.vue";
|
import Tag from "../components/Tag.vue";
|
||||||
import CertificateInfo from "../components/CertificateInfo.vue";
|
import CertificateInfo from "../components/CertificateInfo.vue";
|
||||||
import { getMonitorRelativeURL } from "../util.ts";
|
import { getMonitorRelativeURL } from "../util.ts";
|
||||||
import { URL } from "whatwg-url";
|
import { URL } from "whatwg-url";
|
||||||
|
import DOMPurify from "dompurify";
|
||||||
|
import { marked } from "marked";
|
||||||
import { getResBaseURL } from "../util-frontend";
|
import { getResBaseURL } from "../util-frontend";
|
||||||
import { highlight, languages } from "prismjs/components/prism-core";
|
import { highlight, languages } from "prismjs/components/prism-core";
|
||||||
import "prismjs/components/prism-clike";
|
import "prismjs/components/prism-clike";
|
||||||
|
@ -310,8 +310,7 @@ export default {
|
||||||
Tag,
|
Tag,
|
||||||
CertificateInfo,
|
CertificateInfo,
|
||||||
PrismEditor,
|
PrismEditor,
|
||||||
ScreenshotDialog,
|
ScreenshotDialog
|
||||||
SafeLinks,
|
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -403,6 +402,14 @@ export default {
|
||||||
|
|
||||||
screenshotURL() {
|
screenshotURL() {
|
||||||
return getResBaseURL() + this.monitor.screenshot + "?time=" + this.cacheTime;
|
return getResBaseURL() + this.monitor.screenshot + "?time=" + this.cacheTime;
|
||||||
|
},
|
||||||
|
|
||||||
|
descriptionHTML() {
|
||||||
|
if (this.monitor.description != null) {
|
||||||
|
return DOMPurify.sanitize(marked(this.monitor.description));
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue