Skip to content
Permalink
Browse files Browse the repository at this point in the history
Sanitise tree view text
  • Loading branch information
atampy25 committed Mar 5, 2023
1 parent d56dbe2 commit 5303b45
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/lib/components/MinimalTree.svelte
Expand Up @@ -4,7 +4,7 @@
import "./treeview.css"
import type { Entity } from "$lib/quickentity-types"
import { getReferencedLocalEntity } from "$lib/utils"
import { getReferencedLocalEntity, sanitise } from "$lib/utils"
import { createEventDispatcher, onMount } from "svelte"
import { v4 } from "uuid"
Expand Down Expand Up @@ -73,7 +73,8 @@
dots: true,
icons: true
},
check_callback: true
check_callback: true,
force_text: true
},
search: {
fuzzy: true,
Expand Down Expand Up @@ -155,7 +156,7 @@
: icons.find((a) => entityData.factory.includes(a[0]))
? icons.find((a) => entityData.factory.includes(a[0]))![1]
: "far fa-file",
text: `${entityData.name} (ref ${entityID})`,
text: `${sanitise(entityData.name)} (ref ${entityID})`,
folder: entityData.factory == "[modules:/zentity.class].pc_entitytype" && reverseReferences[entityID].some((a) => a.type == "parent") // for sorting and stuff
})
}
Expand All @@ -166,7 +167,7 @@
id: "comment-" + index,
parent: getReferencedLocalEntity(entry.parent) || "#",
icon: "far fa-sticky-note",
text: entry.name + " (comment)",
text: sanitise(entry.name) + " (comment)",
folder: false // for sorting and stuff
})
Expand Down
9 changes: 5 additions & 4 deletions src/lib/components/Tree.svelte
Expand Up @@ -4,7 +4,7 @@
import "./treeview.css"
import type { Entity, FullRef, Ref, RefWithConstantValue, SubEntity } from "$lib/quickentity-types"
import { changeReferenceToLocalEntity, genRandHex, getReferencedEntities, getReferencedExternalEntities, getReferencedLocalEntity, normaliseToHash, traverseEntityTree } from "$lib/utils"
import { changeReferenceToLocalEntity, genRandHex, getReferencedEntities, getReferencedExternalEntities, getReferencedLocalEntity, normaliseToHash, sanitise, traverseEntityTree } from "$lib/utils"
import { createEventDispatcher, onMount } from "svelte"
import { v4 } from "uuid"
Expand Down Expand Up @@ -96,7 +96,8 @@
dots: true,
icons: true
},
check_callback: true
check_callback: true,
force_text: true
},
search: {
fuzzy: true,
Expand Down Expand Up @@ -751,7 +752,7 @@
: icons.find((a) => entityData.factory.includes(a[0]))
? icons.find((a) => entityData.factory.includes(a[0]))![1]
: "far fa-file",
text: `${entityData.name} (ref ${entityID})`,
text: `${sanitise(entityData.name)} (ref ${entityID})`,
folder: entityData.factory == "[modules:/zentity.class].pc_entitytype" && reverseReferences[entityID].some((a) => a.type == "parent") // for sorting and stuff
})
}
Expand All @@ -762,7 +763,7 @@
id: "comment-" + index,
parent: getReferencedLocalEntity(entry.parent) || "#",
icon: "far fa-sticky-note",
text: entry.name + " (comment)",
text: sanitise(entry.name) + " (comment)",
folder: false // for sorting and stuff
})
Expand Down
7 changes: 7 additions & 0 deletions src/lib/utils.ts
Expand Up @@ -631,3 +631,10 @@ export function changeEntityHashesToFriendly(entity: Entity, friendly: Record<st
export function changeEntityHashesFromFriendly(entity: Entity, friendly: Record<string, string>) {
changeEntityHashesToFriendly(entity, Object.fromEntries(Object.entries(friendly).map((a) => [a[1], a[0]])))
}

export function sanitise(a: string) {
const sanitiser = new DOMParser().parseFromString(`<div></div>`, "text/html")
sanitiser.querySelector("div")!.innerText = a

return sanitiser.querySelector("div")!.innerHTML
}

0 comments on commit 5303b45

Please sign in to comment.