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 = partial_format(format, static_keys)
|
||||||
self.format_keys = {f[1] for f in Formatter().parse(format)}
|
self.format_keys = {f[1] for f in Formatter().parse(format)}
|
||||||
self.call_keys = {
|
self.call_keys = {
|
||||||
"hostname": partial(self.get_meta, "hostname", rs=True),
|
"hostname": partial(self.get_meta, "hostname"),
|
||||||
"username": partial(self.get_meta, "username", rs=True),
|
"username": partial(self.get_meta, "username"),
|
||||||
"comment": partial(self.get_meta, "comment", rs=False),
|
"comment": partial(self.get_meta, "comment"),
|
||||||
"end": self.get_ts_end,
|
"end": self.get_ts_end,
|
||||||
"command_line": self.get_cmdline,
|
"command_line": self.get_cmdline,
|
||||||
}
|
}
|
||||||
|
@ -747,6 +747,12 @@ class ArchiveFormatter(BaseFormatter):
|
||||||
)
|
)
|
||||||
for key in self.used_call_keys:
|
for key in self.used_call_keys:
|
||||||
item_data[key] = self.call_keys[key]()
|
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
|
return item_data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -758,9 +764,8 @@ class ArchiveFormatter(BaseFormatter):
|
||||||
self._archive = Archive(self.manifest, self.name, iec=self.iec)
|
self._archive = Archive(self.manifest, self.name, iec=self.iec)
|
||||||
return self._archive
|
return self._archive
|
||||||
|
|
||||||
def get_meta(self, key, rs):
|
def get_meta(self, key):
|
||||||
value = self.archive.metadata.get(key, "")
|
return self.archive.metadata.get(key, "")
|
||||||
return remove_surrogates(value) if rs else value
|
|
||||||
|
|
||||||
def get_cmdline(self):
|
def get_cmdline(self):
|
||||||
cmdline = map(remove_surrogates, self.archive.metadata.get("cmdline", []))
|
cmdline = map(remove_surrogates, self.archive.metadata.get("cmdline", []))
|
||||||
|
|
Loading…
Reference in New Issue