Sanitize title and icon names

This commit is contained in:
Kovid Goyal
2016-10-21 03:53:31 +05:30
parent 9e40ec413e
commit 067662de94
3 changed files with 10 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ from PyQt5.QtCore import QObject, pyqtSignal
from pyte import charsets as cs, control as ctrl, graphics as g, modes as mo
from .data_types import Line, Cursor, rewrap_lines
from .utils import wcwidth, is_simple_string
from .utils import wcwidth, is_simple_string, sanitize_title
from .unicode import ignore_pat
@@ -405,14 +405,14 @@ class Screen(QObject):
.. note:: This is an XTerm extension supported by the Linux terminal.
"""
self.title_changed.emit(self._decode(param))
self.title_changed.emit(sanitize_title(self._decode(param)))
def set_icon_name(self, param):
"""Sets icon name.
.. note:: This is an XTerm extension supported by the Linux terminal.
"""
self.icon_changed.emit(self._decode(param))
self.icon_changed.emit(sanitize_title(self._decode(param)))
def carriage_return(self):
"""Move the cursor to the beginning of the current line."""

View File

@@ -3,6 +3,7 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import os
import re
import sys
import termios
import struct
@@ -112,3 +113,7 @@ def timeit(name, do_timing=False):
yield
if do_timing:
print('Time for {}: {}'.format(name, monotonic() - st))
def sanitize_title(x):
return re.sub(r'\s+', ' ', re.sub(r'[\0-\x19]', '', x))