Closed keithrbennett closed 6 years ago
I've applied a fix for 99% of the cases; the only case I know if in which it won't work is if there are instances of the name with different numbers of leading spaces. Here is a comment in the code that may be explantory:
Kludge alert: the tabular data does not differentiate between strings with and without leading whitespace. Therefore, we get the data once in tabular format, and another time in XML format.
The XML element will include any leading whitespace. However, it includes all <string>
elements,
many of which are not network names.
As an improved approximation of the correct result, for each network name found in tabular mode, we look to see if there is a corresponding string element with leading whitespace, and, if so, replace it.
This will not behave correctly if a given name has occurrences with different amounts of whitespace, e.g. ' x' and ' x'.
The reason we don't use an XML parser to get the exactly correct result is that we don't want users to need to install any external dependencies in order to run this script.
Network names displayed using the
availnets
andlsavailnets
commands will have any leading spaces stripped. Therefore, if those names are used to try to connect to, connection will fail because the name will be incorrect.This happens because the software is using the MacOS
airport -s
command, which displays network names right justified, such as:There is no way to differentiate a space that is part of the name from a space that is being used for visual padding.
A solution would be to use
airport
's-x
option, which outputs the data in XML in which the leading space is preserved. However, parsing such output would require using an additional gem such asnokogiri
, and one of the intended features of this script is that it should be able to run without the need to install any gems.One possible solution is to have the script check for the existence of Nokogiri, and use it if present.
Another option would be to do a raw text search (as opposed to an XML parse) for any
<string>
elements with leading spaces. I've inspected the output and don't think there would be any false positives, i.e. other fields with that element that could contain leading spaces. Using this approach, it would at minimum be possible to alert the user that some network names may be incorrect.Do be aware, however, that the
airport
output can include multiple records per network name (different access points), so it's conceivable that the same name could occur with different numbers of leading spaces.