mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
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:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user