Explorar o código

format_line: deny access to internal objects

Marian Beermann %!s(int64=8) %!d(string=hai) anos
pai
achega
1924e33ef5
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      src/borg/helpers.py

+ 8 - 0
src/borg/helpers.py

@@ -110,6 +110,10 @@ class PlaceholderError(Error):
     """Formatting Error: "{}".format({}): {}({})"""
 
 
+class InvalidPlaceholder(PlaceholderError):
+    """Invalid placeholder "{}" in string: {}"""
+
+
 def check_extension_modules():
     from . import platform, compress, item
     if hashindex.API_VERSION != '1.1_01':
@@ -780,6 +784,10 @@ class DatetimeWrapper:
 
 
 def format_line(format, data):
+    keys = [f[1] for f in Formatter().parse(format)]
+    for key in keys:
+        if '.' in key or '__' in key:
+            raise InvalidPlaceholder(key, format)
     try:
         return format.format(**data)
     except Exception as e: