mirror of https://github.com/borgbackup/borg.git
make sure hostname and username have no surrogate escapes
if they are present, process them through json_text(). this replaces s-e by "?" for the key and puts the binary representation into key_b64, if needed. likely this is rarely needed.
This commit is contained in:
parent
d090826a37
commit
b3da7d0e72
|
@ -715,9 +715,9 @@ class ArchiveFormatter(BaseFormatter):
|
|||
self.format = partial_format(format, static_keys)
|
||||
self.format_keys = {f[1] for f in Formatter().parse(format)}
|
||||
self.call_keys = {
|
||||
"hostname": partial(self.get_meta, "hostname", rs=True),
|
||||
"username": partial(self.get_meta, "username", rs=True),
|
||||
"comment": partial(self.get_meta, "comment", rs=False),
|
||||
"hostname": partial(self.get_meta, "hostname"),
|
||||
"username": partial(self.get_meta, "username"),
|
||||
"comment": partial(self.get_meta, "comment"),
|
||||
"end": self.get_ts_end,
|
||||
"command_line": self.get_cmdline,
|
||||
}
|
||||
|
@ -747,6 +747,12 @@ class ArchiveFormatter(BaseFormatter):
|
|||
)
|
||||
for key in self.used_call_keys:
|
||||
item_data[key] = self.call_keys[key]()
|
||||
|
||||
# Note: name and comment are validated, should never contain surrogate escapes.
|
||||
# But unsure whether hostname, username could contain surrogate escapes, play safe:
|
||||
for key in "hostname", "username":
|
||||
if key in item_data:
|
||||
item_data.update(text_to_json(key, item_data[key]))
|
||||
return item_data
|
||||
|
||||
@property
|
||||
|
@ -758,9 +764,8 @@ class ArchiveFormatter(BaseFormatter):
|
|||
self._archive = Archive(self.manifest, self.name, iec=self.iec)
|
||||
return self._archive
|
||||
|
||||
def get_meta(self, key, rs):
|
||||
value = self.archive.metadata.get(key, "")
|
||||
return remove_surrogates(value) if rs else value
|
||||
def get_meta(self, key):
|
||||
return self.archive.metadata.get(key, "")
|
||||
|
||||
def get_cmdline(self):
|
||||
cmdline = map(remove_surrogates, self.archive.metadata.get("cmdline", []))
|
||||
|
|
Loading…
Reference in New Issue