Fix escaping in config
This commit is contained in:
parent
0bf918631e
commit
6a725aa87f
1
TODO
1
TODO
@ -8,7 +8,6 @@ Style
|
|||||||
|
|
||||||
_foo = QApplication.instance().obj.foo for global singletons?
|
_foo = QApplication.instance().obj.foo for global singletons?
|
||||||
Use py3.4 Enums with a backport to qutebrowser.utils?
|
Use py3.4 Enums with a backport to qutebrowser.utils?
|
||||||
Make config escaping more clear (escape all ;? Use \ to convert $-signs?)
|
|
||||||
|
|
||||||
Major features
|
Major features
|
||||||
==============
|
==============
|
||||||
|
@ -39,7 +39,7 @@ class ReadConfigParser(ConfigParser):
|
|||||||
configdir: Directory to read the config from.
|
configdir: Directory to read the config from.
|
||||||
fname: Filename of the config file.
|
fname: Filename of the config file.
|
||||||
"""
|
"""
|
||||||
super().__init__(interpolation=None)
|
super().__init__(interpolation=None, comment_prefixes='#')
|
||||||
self.optionxform = lambda opt: opt # be case-insensitive
|
self.optionxform = lambda opt: opt # be case-insensitive
|
||||||
self._configdir = configdir
|
self._configdir = configdir
|
||||||
self._configfile = os.path.join(self._configdir, fname)
|
self._configfile = os.path.join(self._configdir, fname)
|
||||||
|
@ -88,8 +88,9 @@ class ConfigManager(QObject):
|
|||||||
"""Configuration manager for qutebrowser.
|
"""Configuration manager for qutebrowser.
|
||||||
|
|
||||||
Class attributes:
|
Class attributes:
|
||||||
SPECIAL_CHARS: Chars which need escaping when they occur as first char
|
KEY_ESCAPE: Chars which need escaping when they occur as first char
|
||||||
in a line.
|
in a line.
|
||||||
|
VALUE_ESCAPE: Chars to escape inside values.
|
||||||
ESCAPE_CHAR: The char to be used for escaping
|
ESCAPE_CHAR: The char to be used for escaping
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -108,7 +109,8 @@ class ConfigManager(QObject):
|
|||||||
Args: the changed section and option.
|
Args: the changed section and option.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SPECIAL_CHARS = r'\#;['
|
KEY_ESCAPE = r'\#['
|
||||||
|
VALUE_ESCAPE = r'\$'
|
||||||
ESCAPE_CHAR = '\\'
|
ESCAPE_CHAR = '\\'
|
||||||
|
|
||||||
changed = pyqtSignal(str, str)
|
changed = pyqtSignal(str, str)
|
||||||
@ -198,11 +200,15 @@ class ConfigManager(QObject):
|
|||||||
"""Get the option items as string for section."""
|
"""Get the option items as string for section."""
|
||||||
lines = []
|
lines = []
|
||||||
for optname, option in section.items():
|
for optname, option in section.items():
|
||||||
for c in self.SPECIAL_CHARS:
|
value = option.get_first_value(startlayer='conf')
|
||||||
|
for c in self.KEY_ESCAPE:
|
||||||
if optname.startswith(c):
|
if optname.startswith(c):
|
||||||
optname = optname.replace(c, self.ESCAPE_CHAR + c, 1)
|
optname = optname.replace(c, self.ESCAPE_CHAR + c, 1)
|
||||||
keyval = '{} = {}'.format(optname, option.get_first_value(
|
for c in self.VALUE_ESCAPE:
|
||||||
startlayer='conf'))
|
logging.warn("{} Before escaping {}: {}".format(optname, c, value))
|
||||||
|
value = value.replace(c, self.ESCAPE_CHAR + c)
|
||||||
|
logging.warn("After escaping {}: {}".format(c, value))
|
||||||
|
keyval = '{} = {}'.format(optname, value)
|
||||||
lines.append(keyval)
|
lines.append(keyval)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@ -218,6 +224,8 @@ class ConfigManager(QObject):
|
|||||||
for k, v in cp[secname].items():
|
for k, v in cp[secname].items():
|
||||||
if k.startswith(self.ESCAPE_CHAR):
|
if k.startswith(self.ESCAPE_CHAR):
|
||||||
k = k[1:]
|
k = k[1:]
|
||||||
|
for c in self.VALUE_ESCAPE:
|
||||||
|
v = v.replace(self.ESCAPE_CHAR + c, c)
|
||||||
try:
|
try:
|
||||||
self.set('conf', secname, k, v)
|
self.set('conf', secname, k, v)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
|
@ -50,6 +50,11 @@ FIRST_COMMENT = """
|
|||||||
# This is the default config, so if you want to remove anything from
|
# This is the default config, so if you want to remove anything from
|
||||||
# here (as opposed to change/add), for example a keybinding, set it to
|
# here (as opposed to change/add), for example a keybinding, set it to
|
||||||
# an empty value.
|
# an empty value.
|
||||||
|
#
|
||||||
|
# You will need to escape the following value:
|
||||||
|
# - # at the start of the line (at the first position of the key) (\#)
|
||||||
|
# - $ in a value (\$)
|
||||||
|
# - \ in a value (\\)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user