Skip to content

Commit 0c57b0a

Browse files
committed
[fix] Fixed UCI name escaping in uci-autoname script
The openwisp-uci-autoname script did not always escape renamed UCI sections, therefore in some cases the new name was invalid, which caused the section to be removed entirely.
1 parent 04d8b33 commit 0c57b0a

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

openwisp-config/files/sbin/openwisp-uci-autoname.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,22 @@ for file in lfs.dir(standard_path) do
8080
new_name = 'led_' .. string.lower(section['name'])
8181
elseif file == 'wireless' and section['.type'] == 'wifi-iface' then
8282
if section['ifname'] == nil then
83-
new_name = 'wifi_' .. getUCIName(
83+
new_name = 'wifi_' .. (
8484
standard:get('network', section['network'], 'ifname')
8585
)
8686
else
87-
new_name = 'wifi_' .. getUCIName(section['ifname'])
87+
new_name = 'wifi_' .. section['ifname']
8888
end
8989
else
90-
new_name = nextAvailableName(getUCIName(section['.type']))
90+
new_name = nextAvailableName(section['.type'])
9191
end
9292
-- make sure the new name is unique
9393
if all_names[new_name] then
9494
new_name = nextAvailableName(new_name .. '_')
9595
end
9696
all_names[new_name] = true
97-
section['.name'] = new_name
97+
-- make sure name is valid
98+
section['.name'] = getUCIName(new_name)
9899
section['.anonymous'] = false
99100
utils.write_uci_section(output, file, section)
100101
output:reorder(file, section['.name'], index)

openwisp-config/tests/config/network

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ config interface 'lan'
1414
option ip6assign '60'
1515
option force_link '0'
1616

17+
config device
18+
option name 'eth0.2'
19+
option macaddr '00:00:00:00:00:11'
20+
1721
config interface 'wan'
18-
option ifname 'eth0.2'
22+
option device 'eth0.2'
1923
option proto 'none'
2024
option test_restore '1'
2125

openwisp-config/tests/test_uci_autoname.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ function TestUciAutoname.test_default_behaviour()
4242
-- ensure rest of config options are present
4343
luaunit.assertNotNil(string.find(networkContents, "config interface 'loopback'"))
4444
luaunit.assertNotNil(string.find(networkContents, "config interface 'lan'"))
45+
-- ensure device eth0.2 is renamed
46+
luaunit.assertNotNil(string.find(networkContents, "config device 'device_eth0_2'"))
47+
luaunit.assertNotNil(string.find(networkContents, "option macaddr '00:00:00:00:00:11'"))
4548
-- check wireless
4649
local wirelessFile = io.open(write_dir .. 'wireless')
4750
luaunit.assertNotNil(wirelessFile)

0 commit comments

Comments
 (0)