Escape server names before showing them, and search the plain name

This commit is contained in:
Starystars67 committed 2026-10-08 21:42:23 +01:00
1 parent f45156a143
commit 9f20c38abe
1 file changed
+18 -2
+18 -2
View File
@@ -289,7 +289,7 @@ const filteredServers = computed(() => {
if (searchQuery.value) {
const query = searchQuery.value.toLowerCase()
const matchesSearch =
cleanServerName(server.sname).toLowerCase().includes(query) ||
plainServerName(server.sname).toLowerCase().includes(query) ||
(server.sdesc && server.sdesc.toLowerCase().includes(query)) ||
formatMapName(server.map).toLowerCase().includes(query) ||
server.owner.toLowerCase().includes(query)
@@ -352,7 +352,23 @@ function applyCode(string, codes) {
}
// eslint-disable-next-line no-control-regex
string = string.replace(/\x00*/g, '')
return `<span style="${style}">${string}</span>`
// The name is set by whoever hosts the server and is shown as HTML (v-html)
// so the colours can apply: the text must be escaped, never trusted.
return `<span style="${style}">${escapeHtml(string)}</span>`
}
function escapeHtml(text) {
return text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
}
// The name as plain text, colour codes removed: what the search looks through.
function plainServerName(name) {
return name.replace(/\^.{1}/g, '')
}
function cleanServerName(name) {