Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions example/src/directives/safeHtml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import DOMPurify from 'dompurify'
import type { App, DirectiveBinding } from 'vue'

export default {
install(app: App) {
app.directive('safe-html', {
beforeMount(el: HTMLElement, binding: DirectiveBinding<string>) {
el.innerHTML = DOMPurify.sanitize(binding.value)
},
updated(el: HTMLElement, binding: DirectiveBinding<string>) {
if (binding.value !== binding.oldValue) {
el.innerHTML = DOMPurify.sanitize(binding.value)
}
}
})
}
}
7 changes: 6 additions & 1 deletion example/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { createApp } from "vue"
import "bootstrap"
import "bootstrap/dist/css/bootstrap.css"
import safeHtmlDirective from "./directives/safeHtml"

import App from "./App.vue"

createApp(App).mount("#app")
const app = createApp(App)

app.use(safeHtmlDirective)

app.mount("#app")

declare global {
interface Window {
Expand Down
51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"bootstrap": "^5.3.8",
"d3": "^7.9.0",
"d3-flextree": "^2.1.2",
"dompurify": "^3.3.0",
"highlight.js": "^11.11.1",
"humanize-duration": "^3.33.0",
"lodash": "^4.17.21",
Expand All @@ -48,6 +49,7 @@
"@eslint/eslintrc": "^3.3.0",
"@eslint/js": "^9.21.0",
"@types/d3": "^7.4.3",
"@types/dompurify": "^3.0.5",
"@types/humanize-duration": "^3.27.1",
"@types/lodash": "^4.14.202",
"@types/node": "^24.7.1",
Expand Down
8 changes: 4 additions & 4 deletions src/components/DiagramRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ watch(
class="mb-0"
/>
<template v-else-if="diagramViewOptions.metric == Metric.rows">
<div v-html="rowsTooltip"></div>
<div v-safe-html="rowsTooltip"></div>
</template>
<template v-else-if="diagramViewOptions.metric == Metric.estimate_factor">
<div v-html="estimateFactorTooltip"></div>
<div v-safe-html="estimateFactorTooltip"></div>
</template>
<template v-else-if="diagramViewOptions.metric == Metric.cost">
<div v-html="costTooltip"></div>
<div v-safe-html="costTooltip"></div>
</template>
<template v-else-if="diagramViewOptions.metric == Metric.buffers">
<div
v-html="buffersByLocationTooltip(diagramViewOptions.buffersMetric)"
v-safe-html="buffersByLocationTooltip(diagramViewOptions.buffersMetric)"
></div
></template>
</template>
Expand Down
16 changes: 8 additions & 8 deletions src/components/GridRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const showDetails = ref<boolean>(false)
></SeverityBullet>
<span class="flex-grow-1">
<span
v-html="factor(node[NodeProp.PLANNER_ESTIMATE_FACTOR] || 0)"
v-safe-html="factor(node[NodeProp.PLANNER_ESTIMATE_FACTOR] || 0)"
></span>
<span
v-if="
Expand Down Expand Up @@ -371,18 +371,18 @@ const showDetails = ref<boolean>(false)
</template>
<template v-else-if="node[NodeProp.ALIAS]">
<span class="text-secondary">on</span>
<span v-html="keysToString(node[NodeProp.ALIAS] as string)"></span>
<span v-safe-html="keysToString(node[NodeProp.ALIAS] as string)"></span>
</template>
<template v-if="node[NodeProp.GROUP_KEY]">
<span class="text-secondary">by</span>
<span
v-html="keysToString(node[NodeProp.GROUP_KEY] as string)"
v-safe-html="keysToString(node[NodeProp.GROUP_KEY] as string)"
></span>
</template>
<template v-if="node[NodeProp.SORT_KEY]">
<span class="text-secondary">by</span>
<span
v-html="
v-safe-html="
sortKeys(
node[NodeProp.SORT_KEY] as string[],
node[NodeProp.PRESORTED_KEY] as string[],
Expand All @@ -393,13 +393,13 @@ const showDetails = ref<boolean>(false)
<template v-if="node[NodeProp.INDEX_NAME]">
<span class="text-secondary">using</span>
<span
v-html="keysToString(node[NodeProp.INDEX_NAME] as string)"
v-safe-html="keysToString(node[NodeProp.INDEX_NAME] as string)"
></span>
</template>
<template v-if="node[NodeProp.HASH_CONDITION]">
<span class="text-secondary">on</span>
<span
v-html="keysToString(node[NodeProp.HASH_CONDITION] as string)"
v-safe-html="keysToString(node[NodeProp.HASH_CONDITION] as string)"
></span>
</template>
<template v-if="node[NodeProp.CTE_NAME]">
Expand All @@ -424,7 +424,7 @@ const showDetails = ref<boolean>(false)
>
<span class="node-type">{{ node[NodeProp.NODE_TYPE] }} Node</span>
<span
v-html="getNodeTypeDescription(node[NodeProp.NODE_TYPE])"
v-safe-html="getNodeTypeDescription(node[NodeProp.NODE_TYPE])"
></span>
</div>
<ul class="nav nav-tabs mt-1">
Expand Down Expand Up @@ -476,7 +476,7 @@ const showDetails = ref<boolean>(false)
<div
class="tab-pane p-1 border border-top-0 overflow-auto font-monospace"
:class="{ 'show active': activeTab === 'output' }"
v-html="formattedProp('OUTPUT')"
v-safe-html="formattedProp('OUTPUT')"
style="max-height: 200px"
@mousewheel.stop
></div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MiscDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function calculateProps() {
<template v-for="(prop, key) in nodeProps" :key="key">
<tr v-if="shouldShowProp(prop.key, prop.value)">
<td width="40%">{{ prop.key }}</td>
<td v-html="formatNodeProp(prop.key, prop.value)"></td>
<td v-safe-html="formatNodeProp(prop.key, prop.value)"></td>
</tr>
</template>
</table>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Plan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function updateNodeSize(node: Node, size: [number, number]) {
<pre
class="small p-2 mb-0"
style="max-height: 200px"
><code v-html="planSource"></code></pre>
><code v-safe-html="planSource"></code></pre>
</div>
<Copy :content="planSource" />
</div>
Expand Down Expand Up @@ -743,7 +743,7 @@ function updateNodeSize(node: Node, size: [number, number]) {
<div class="overflow-auto flex-grow-1">
<pre
class="small p-2 mb-0"
><code v-html="json_(planSource)"></code></pre>
><code v-safe-html="json_(planSource)"></code></pre>
</div>
<Copy :content="planSource" />
</div>
Expand All @@ -757,7 +757,7 @@ function updateNodeSize(node: Node, size: [number, number]) {
<div class="overflow-auto flex-grow-1">
<pre
class="small p-2 mb-0"
><code v-html="pgsql_(queryText)"></code></pre>
><code v-safe-html="pgsql_(queryText)"></code></pre>
</div>
</div>
<Copy :content="queryText" />
Expand Down
12 changes: 6 additions & 6 deletions src/components/PlanNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function centerCte() {
>
<span class="text-secondary">on</span>
<span
v-html="keysToString(node[NodeProp.ALIAS] as string)"
v-safe-html="keysToString(node[NodeProp.ALIAS] as string)"
></span>
</div>
<div
Expand All @@ -199,7 +199,7 @@ function centerCte() {
>
<span class="text-secondary">by</span>
<span
v-html="keysToString(node[NodeProp.GROUP_KEY] as string)"
v-safe-html="keysToString(node[NodeProp.GROUP_KEY] as string)"
></span>
</div>
<div
Expand All @@ -208,7 +208,7 @@ function centerCte() {
>
<span class="text-secondary">by</span>
<span
v-html="
v-safe-html="
sortKeys(
node[NodeProp.SORT_KEY] as string[],
node[NodeProp.PRESORTED_KEY] as string[],
Expand All @@ -222,7 +222,7 @@ function centerCte() {
>
<span class="text-secondary">using</span>
<span
v-html="keysToString(node[NodeProp.INDEX_NAME] as string)"
v-safe-html="keysToString(node[NodeProp.INDEX_NAME] as string)"
></span>
</div>
<div
Expand All @@ -231,7 +231,7 @@ function centerCte() {
>
<span class="text-secondary">on</span>
<span
v-html="keysToString(node[NodeProp.HASH_CONDITION] as string)"
v-safe-html="keysToString(node[NodeProp.HASH_CONDITION] as string)"
></span>
</div>
<div v-if="node[NodeProp.CTE_NAME]">
Expand Down Expand Up @@ -269,7 +269,7 @@ function centerCte() {
<span class="text-secondary"
>{{ viewOptions.highlightType }}:</span
>
<span v-html="highlightValue"></span>
<span v-safe-html="highlightValue"></span>
</span>
</div>
</div>
Expand Down
Loading