mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-10-07 13:37:09 -04:00
BE: escape backslashes when serializing string settings to app.conf
app.conf is written by util.php saveSettings() as Python source and later
compiled/exec'd by the backend. String settings were emitted into
single-quoted Python literals with only ' encoded (as {s-quote}), so
backslashes were written raw. A regex such as 192\.0\.2\..* then produced
"SyntaxWarning: invalid escape sequence '\.'", valid Python escapes such as
\n were silently reinterpreted, and a trailing backslash made the file fail
to compile.
Move the encoder into a side-effect-free helper, app_conf_encode.php, as
encode_python_string(). It now doubles backslashes before the existing
{s-quote} replacement, so backslashes round-trip unchanged through app.conf
serialization and Python parsing, while single quotes keep using the legacy
{s-quote} placeholder. Both scalar string and array string serialization use
the helper.
Add regression tests that run the real PHP helper through the PHP CLI,
compile the generated source with warnings promoted to errors, and check
the scalar and array round trips.
This commit is contained in:
1 parent
0d60071d49
commit
6dbd3f8f29
3 files changed
+117
-7
No files matched your search
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
//------------------------------------------------------------------------------
|
||||
// NetAlertX
|
||||
// Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
//
|
||||
// app_conf_encode.php - Side-effect-free helpers for serializing app.conf values
|
||||
//------------------------------------------------------------------------------
|
||||
# Puche 2021 / 2022+ jokob support@netalertx.com GNU GPLv3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Encode a string for use inside a single-quoted Python literal in app.conf.
|
||||
* Doubles backslashes so they round-trip unchanged, and replaces ' with the
|
||||
* legacy {s-quote} placeholder that the backend converts back per use.
|
||||
*/
|
||||
function encode_python_string($val) {
|
||||
return str_replace(['\\', '\''], ['\\\\', '{s-quote}'], $val);
|
||||
}
|
||||
Reference in new issue
Block a user