Escape special INI chars in ConfigManager
This commit is contained in:
parent
ede8b67b80
commit
35ba97d338
1
TODO
1
TODO
@ -3,7 +3,6 @@ Bugs
|
|||||||
|
|
||||||
All kind of FIXMEs
|
All kind of FIXMEs
|
||||||
Changing completion models is awfully slow
|
Changing completion models is awfully slow
|
||||||
values starting with ; need to be escaped
|
|
||||||
|
|
||||||
Style
|
Style
|
||||||
=====
|
=====
|
||||||
|
@ -87,6 +87,11 @@ class ConfigManager(QObject):
|
|||||||
|
|
||||||
"""Configuration manager for qutebrowser.
|
"""Configuration manager for qutebrowser.
|
||||||
|
|
||||||
|
Class attributes:
|
||||||
|
SPECIAL_CHARS: Chars which need escaping when they occur as first char
|
||||||
|
in a line.
|
||||||
|
ESCAPE_CHAR: The char to be used for escaping
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
sections: The configuration data as an OrderedDict.
|
sections: The configuration data as an OrderedDict.
|
||||||
_configparser: A ReadConfigParser instance to load the config.
|
_configparser: A ReadConfigParser instance to load the config.
|
||||||
@ -103,6 +108,9 @@ class ConfigManager(QObject):
|
|||||||
Args: the changed section and option.
|
Args: the changed section and option.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
SPECIAL_CHARS = r'\#;['
|
||||||
|
ESCAPE_CHAR = '\\'
|
||||||
|
|
||||||
changed = pyqtSignal(str, str)
|
changed = pyqtSignal(str, str)
|
||||||
style_changed = pyqtSignal(str, str)
|
style_changed = pyqtSignal(str, str)
|
||||||
|
|
||||||
@ -190,6 +198,9 @@ 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:
|
||||||
|
if optname.startswith(c):
|
||||||
|
optname = optname.replace(c, self.ESCAPE_CHAR + c, 1)
|
||||||
keyval = '{} = {}'.format(optname, option.get_first_value(
|
keyval = '{} = {}'.format(optname, option.get_first_value(
|
||||||
startlayer='conf'))
|
startlayer='conf'))
|
||||||
lines.append(keyval)
|
lines.append(keyval)
|
||||||
@ -205,6 +216,8 @@ class ConfigManager(QObject):
|
|||||||
if secname not in cp:
|
if secname not in cp:
|
||||||
continue
|
continue
|
||||||
for k, v in cp[secname].items():
|
for k, v in cp[secname].items():
|
||||||
|
if k.startswith(self.ESCAPE_CHAR):
|
||||||
|
k = k[1:]
|
||||||
try:
|
try:
|
||||||
self.set('conf', secname, k, v)
|
self.set('conf', secname, k, v)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user