Skip to content

Commit ec90d55

Browse files
committed
[fix] Avoid replacing True/False substrings in UCI string values
1 parent e1e9b41 commit ec90d55

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

netjsonconfig/backends/openwrt/renderer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from ..base.renderer import BaseRenderer
24

35

@@ -16,8 +18,7 @@ def cleanup(self, output):
1618
.replace("\noption", "\n\toption")
1719
.replace("\nlist", "\n\tlist")
1820
)
19-
import re
20-
# convert 'True' to '1' and 'False' to '0', but only on whole words bounded by quotes e.g. 'True' -> '1'
21+
# convert True to 1 and False to 0 (exact match only, not substrings)
2122
output = re.sub(r"'True'", "'1'", output)
2223
output = re.sub(r"'False'", "'0'", output)
2324
# max 2 consecutive \n delimiters

tests/openwrt/test_wireless.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def test_render_wifi_issue_250_false_ssid(self):
7777
expected_uci = self._wifi_uci.replace("'MyWifiAP'", "'FalseGait Living Guest'")
7878
self.assertEqual(o.render(), self._tabs(expected_uci))
7979

80-
8180
def test_parse_wifi_interface(self):
8281
o = OpenWrt(native=self._wifi_uci)
8382
self.assertDictEqual(o.config, self._wifi_netjson)

0 commit comments

Comments
 (0)