Skip to content
  • Christian Kellner's avatar
    exported: use a whitelist for object-path chars · 298b180a
    Christian Kellner authored
    When generating the object-path from the object-id, instead of
    using a blacklist of forbidden chars, use a whitelist of the
    allowed object-path chars. Non-valid chars are replaced by '_'.
    This assures we always have a valid, albeit maybe ugly, object-
    path. Extend the test to include a object id with invalid chars.
    
    python3 script to generate the #define from the freedesktop.org
    specification:
    import itertools
    
    def main():
        """
        Valid Object Paths:
        [...]
        Each element must only contain the ASCII characters "[A-Z][a-z][0-9]_"
        [...]
          from https://dbus.freedesktop.org/doc/dbus-specification.html
        """
    
        name = "DBUS_OPATH_VALID_CHARS"
        chars = ''.join(
            itertools.chain(
                *[map(chr, range(ord(s), ord(e) + 1)) for s, e in [
                    ('A', 'Z'),
                    ('a', 'z'),
                    ('0', '9'),
                    ('_', '_')]]))
        print('#define %s "%s"' % (name, chars))
    
    if __name__ == '__main__':
        main()
    298b180a