Skip to content

Commit 15030dc

Browse files
authored
Fix SSID UTF8 Encoding (#317)
1 parent 162d3a9 commit 15030dc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

System.Device.Wifi/WifiAdapter.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System;
77
using System.Runtime.CompilerServices;
8+
using System.Text;
89

910
namespace System.Device.Wifi
1011
{
@@ -91,14 +92,16 @@ private WifiAvailableNetwork[] ParseNativeReports(byte[] nativeReport)
9192
WifiNetworks[index].Bsid = BitConverter.ToString(nativeReport, bytePos, 6);
9293
bytePos += 6;
9394

94-
// need to convert this programmatically to prevent referencing System.Text
95-
char[] rawSsid = new char[33];
96-
for (int i = 0; i < 33; i++)
95+
byte[] rawSsid = new byte[33];
96+
Array.Copy(nativeReport, bytePos, rawSsid, 0, 33);
97+
98+
int ssidLength = Array.IndexOf(rawSsid, (byte)0);
99+
if (ssidLength < 0)
97100
{
98-
rawSsid[i] = (char)nativeReport[bytePos + i];
101+
ssidLength = 33;
99102
}
100-
101-
WifiNetworks[index].Ssid = new string(rawSsid, 0, 33);
103+
104+
WifiNetworks[index].Ssid = Encoding.UTF8.GetString(rawSsid, 0, ssidLength);
102105
bytePos += 33;
103106

104107
WifiNetworks[index]._rssi = (sbyte)nativeReport[bytePos];

0 commit comments

Comments
 (0)