Improve parser to ignore stanzas that are commented out or not formatted by this program.

This commit is contained in:
mmcwilliams 2018-01-01 00:19:07 -05:00
parent bcc29424da
commit 5496881616
1 changed files with 4 additions and 4 deletions

View File

@ -23,19 +23,19 @@ function parseConfig (str) {
const lines = str.split('\n')
let network = {}
for (let line of lines) {
if (line.indexOf('network={') !== -1) {
if (line.substring(0, 9) === 'network={') {
network = {}
network.raw = line
} else if (line.indexOf('ssid=') !== -1) {
} else if (network.raw && line.indexOf('ssid=') !== -1) {
network.ssid = line.replace('ssid=', '').trim().replace(quoteRe, '')
if (network.raw) {
network.raw += '\n' + line
}
} else if (line.indexOf('}') !== -1) {
} else if (network.raw && line.substring(0, 1) === '}') {
network.raw += '\n' + line
networks.push(network)
network = {}
} else if (network.ssid) {
} else if (network.raw) {
network.raw += '\n' + line
}
}