Graphics protocol: Only delete temporary image-data files if they are in a known temporary file location

This commit is contained in:
Kovid Goyal
2018-12-11 10:00:43 +05:30
parent 4a8562a85f
commit d20c65ef80
5 changed files with 41 additions and 7 deletions

View File

@@ -2,13 +2,16 @@
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import os
import tempfile
from kitty.config import build_ansi_color_table, defaults
from kitty.fast_data_types import (
REVERSE, ColorProfile, Cursor as C, HistoryBuf, LineBuf,
parse_input_from_terminal, wcswidth, wcwidth, truncate_point_for_length
parse_input_from_terminal, truncate_point_for_length, wcswidth, wcwidth
)
from kitty.rgb import to_color
from kitty.utils import sanitize_title
from kitty.utils import is_path_in_temp_dir, sanitize_title
from . import BaseTest, filled_cursor, filled_history_buf, filled_line_buf
@@ -384,6 +387,12 @@ class TestDataTypes(BaseTest):
tp('a\033', '_', 'x\033', '\\b', text='a b', apc='x')
tp('a\033_', 'x', '\033', '\\', 'b', text='a b', apc='x')
for prefix in ('/tmp', tempfile.gettempdir()):
for path in ('a.png', 'x/b.jpg', 'y/../c.jpg'):
self.assertTrue(is_path_in_temp_dir(os.path.join(prefix, path)))
for path in ('/home/xy/d.png', '/tmp/../home/x.jpg'):
self.assertFalse(is_path_in_temp_dir(os.path.join(path)))
def test_color_profile(self):
c = ColorProfile()
c.update_ansi_color_table(build_ansi_color_table())