[chirp_devel] [PATCH] [FT-1D] Sanitize aprs message string before loading them in settings

Marco Filippi IZ3GME
Thu May 21 02:46:14 PDT 2015


# HG changeset patch
# User Marco Filippi <iz3gme.marco at gmail.com>
# Date 1432201135 -7200
#      Thu May 21 11:38:55 2015 +0200
# Node ID 8c887ff64aaf1072354f6461a25d01fcacdd555a
# Parent  d5d7c8a069537939ec39575b6eabbc36c40e5934
[FT-1D] Sanitize aprs message string before loading them in settings

Aprs messages can contain non printable chars, replace them with * to obtain
a printable string

Fix #2509

diff --git a/chirp/chirp_common.py b/chirp/chirp_common.py
--- a/chirp/chirp_common.py
+++ b/chirp/chirp_common.py
@@ -1462,3 +1462,12 @@
 
     return ((txmode, txval, txpol),
             (rxmode, rxval, rxpol))
+
+
+def sanitize_string(astring, validcharset=CHARSET_ASCII, replacechar='*'):
+    myfilter = ''.join(
+        [
+            [replacechar, chr(x)][chr(x) in validcharset]
+            for x in xrange(256)
+        ])
+    return astring.translate(myfilter)
diff --git a/chirp/drivers/ft1d.py b/chirp/drivers/ft1d.py
--- a/chirp/drivers/ft1d.py
+++ b/chirp/drivers/ft1d.py
@@ -957,16 +957,21 @@
 
         for index in range(0, 60):
             if aprs_msg[index].flag != 255:
+                astring = \
+                    str(aprs_msg[index].dst_callsign).partition("\xFF")[0]
+
                 val = RadioSettingValueString(
-                    0, 9, str(aprs_msg[index].dst_callsign).rstrip("\xFF") +
+                    0, 9, chirp_common.sanitize_string(astring) +
                     "-%d" % aprs_msg[index].dst_callsign_ssid)
                 rs = RadioSetting(
                     "aprs_msg.dst_callsign%d" % index,
                     "Dst Callsign %d" % index, val)
                 menu.append(rs)
 
+                astring = \
+                    str(aprs_msg[index].path_and_body).partition("\xFF")[0]
                 val = RadioSettingValueString(
-                    0, 66, str(aprs_msg[index].path_and_body).rstrip("\xFF"))
+                    0, 66, chirp_common.sanitize_string(astring))
                 rs = RadioSetting(
                     "aprs_msg.path_and_body%d" % index, "Body", val)
                 menu.append(rs)



More information about the chirp_devel mailing list