Decode escaped SSIDs after status parsing
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user