Keep control escapes safe in SSID labels

This commit is contained in:
David Heinemeier Hansson
2026-07-31 19:13:52 -07:00
parent bac31ff892
commit a734713c42
2 changed files with 17 additions and 12 deletions
+13 -10
View File
@@ -92,18 +92,21 @@ 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 {
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))) {
var hex = raw.substring(i + 2, i + 4)
var byte = parseInt(hex, 16)
encoded += byte < 32 || byte === 127 ? encodeURIComponent(raw.substring(i, i + 4)) : "%" + hex
i += 3
} else {
encoded += encodeURIComponent(raw[i])
}
}
return decodeURIComponent(encoded)
} catch (error) {
return raw