NetworkManager: Decode SSID to UTF-8 (#10864)

wpa_supplicant returns all non-ASCII SSIDs as raw bytes in the form
\x0a. We interpret these bytes as UTF-8, and make sure that all invalid
characters are replaced with a �.
This commit is contained in:
Wim de With
2023-08-31 19:29:30 +02:00
committed by GitHub
parent 1ef7821b66
commit 599a3034ca
3 changed files with 48 additions and 5 deletions

View File

@@ -943,7 +943,7 @@ function NetworkMgr:reconnectOrShowNetworkMenu(complete_callback, interactive)
end
UIManager:show(InfoMessage:new{
tag = "NetworkMgr", -- for crazy KOSync purposes
text = T(_("Connected to network %1"), BD.wrap(ssid)),
text = T(_("Connected to network %1"), BD.wrap(self.decodeSSID(ssid))),
timeout = 3,
})
else
@@ -995,6 +995,23 @@ function NetworkMgr:setWirelessBackend(name, options)
require("ui/network/"..name).init(self, options)
end
function NetworkMgr.decodeSSID(text)
local decode = function(b)
local c = string.char(tonumber(b, 16))
-- This is a hack that allows us to make sure that any decoded backslash
-- does not get replaced in the step that replaces double backslashes.
if c == "\\" then
return "\\\\"
else
return c
end
end
local decoded = text:gsub("%f[\\]\\x(%x%x)", decode)
decoded = decoded:gsub("\\\\", "\\")
return util.fixUtf8(decoded, "<EFBFBD>")
end
-- set network proxy if global variable G_defaults:readSetting("NETWORK_PROXY") is defined
if G_defaults:readSetting("NETWORK_PROXY") then
NetworkMgr:setHTTPProxy(G_defaults:readSetting("NETWORK_PROXY"))