Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion test/wpa_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ var WPA_CLI_SCAN_RESULTS = [
'2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi2'
].join('\n');

var WPA_CLI_SCAN_RESULTS_UTF8 = [
'bssid / frequency / signal level / flags / ssid',
'2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] Fake\xc3\x96Wifi',
'2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi2'
].join('\n');

var WPA_CLI_SCAN_NORESULTS = [
''
].join('\n');
Expand Down Expand Up @@ -605,6 +611,30 @@ describe('wpa_cli', function() {
});
});

it('scan_results COMPLETED, correctly parse utf8', function(done) {
this.OUTPUT = WPA_CLI_SCAN_RESULTS_UTF8;
wpa_cli.scan_results('wlan0', function(err, results) {
should(results).eql([
{
bssid: '2c:f5:d3:02:ea:d9',
frequency: 2472,
signalLevel: -31,
flags: '[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]',
ssid: 'FakeÖWifi'
},
{
bssid: '2c:f5:d3:02:ea:d9',
frequency: 2472,
signalLevel: -31,
flags: '[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]',
ssid: 'FakeWifi2'
}
]);

done();
});
});

it('should handle errors', function(done) {
wpa_cli.exec = function(command, callback) {
callback('error');
Expand Down Expand Up @@ -657,4 +687,4 @@ describe('wpa_cli', function() {
});
});
});
});
});
10 changes: 7 additions & 3 deletions wpa_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ function parse_command_interface(callback) {
};
}

function decodeUtf8(string) {
return Buffer.from(string, 'ascii').toString('utf8');
}

/**
* Parses the results of a scan_result request.
*
Expand All @@ -192,7 +196,7 @@ function parse_scan_results(block) {
var match;
var results = [];
var lines;

lines = block.split('\n').map(function(item) { return item + "\n"; });
lines.forEach(function(entry){
var parsed = {};
Expand All @@ -213,7 +217,7 @@ function parse_scan_results(block) {
}

if ((match = entry.match(/\t([^\t]{1,32}(?=\n))/))) {
parsed.ssid = match[1];
parsed.ssid = decodeUtf8(match[1]);
}

if(!(Object.keys(parsed).length === 0 && parsed.constructor === Object)){
Expand Down Expand Up @@ -413,4 +417,4 @@ function save_config(interface, callback) {
'save_config'].join(' ');

return this.exec(command, parse_command_interface(callback));
}
}