Decode escaped SSIDs after status parsing

This commit is contained in:
David Heinemeier Hansson
2026-07-31 19:08:37 -07:00
parent b64f5e51fb
commit bac31ff892
3 changed files with 32 additions and 2 deletions
+22 -1
View File
@@ -90,7 +90,25 @@ function parseBandStatus(raw) {
}
}
function decodeIwSsid(value) {
var raw = String(value || "")
var encoded = ""
for (var i = 0; i < raw.length; i++) {
if (raw[i] === "\\" && raw[i + 1] === "x" && /^[0-9a-f]{2}$/i.test(raw.substring(i + 2, i + 4))) {
encoded += "%" + raw.substring(i + 2, i + 4)
i += 3
} else {
encoded += encodeURIComponent(raw[i])
}
}
try {
return decodeURIComponent(encoded)
} catch (error) {
return raw
}
}
function parseKeyValue(raw) {
var next = {}
@@ -100,7 +118,9 @@ function parseKeyValue(raw) {
if (!line) continue
var idx = line.indexOf("\t")
if (idx === -1) continue
next[line.substring(0, idx)] = line.substring(idx + 1).trim()
var key = line.substring(0, idx)
var value = line.substring(idx + 1)
next[key] = key === "ssid" ? decodeIwSsid(value) : value.trim()
}
return next
}
@@ -319,6 +339,7 @@ if (typeof module !== "undefined") {
bandSectionTitle: bandSectionTitle,
bandTooltip: bandTooltip,
parseBandStatus: parseBandStatus,
decodeIwSsid: decodeIwSsid,
parseKeyValue: parseKeyValue,
throughputState: throughputState,
pingLatencyState: pingLatencyState,