diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2015-10-12 15:45:36 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2015-10-12 15:45:50 +0200 |
| commit | 2edcec94e9e3f55313d4aa6d784e52ce37f1ba0e (patch) | |
| tree | e24a11c2c6d4984de4ca6420beda9148a97ec1d6 /src/ConfigBase.cpp | |
| parent | 66a0030f5d120a477128ea183451f7a7f9c33bb7 (diff) | |
| download | manager-2edcec94e9e3f55313d4aa6d784e52ce37f1ba0e.tar.gz manager-2edcec94e9e3f55313d4aa6d784e52ce37f1ba0e.zip | |
Add escaping in ConfigBase
Diffstat (limited to 'src/ConfigBase.cpp')
| -rw-r--r-- | src/ConfigBase.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/ConfigBase.cpp b/src/ConfigBase.cpp index d895e80..9f62d77 100644 --- a/src/ConfigBase.cpp +++ b/src/ConfigBase.cpp @@ -10,7 +10,7 @@ void ConfigBase::addConfigValue(QString name, ConfigValueBase* value) void ConfigBase::setConfigValue(const QString &name, const QString &value) { ConfigValueBase& configValue = getConfigValue(name); - configValue.setValue(value); + configValue.setValue(Util::unescape(value)); } QString ConfigBase::getConfigValueLine(const QString &name) @@ -26,7 +26,7 @@ QString ConfigBase::getConfigValueLine(const QString &name) const QMap<QString, QString>& values = (dynamic_cast<ConfigValueMap*>(&value))->getValues(); foreach(const QString& mapKey, values.keys()) { - ret += name + "[" + mapKey + "]" + " = " + values.value(mapKey) + "\n"; + ret += name + "[" + Util::escape(mapKey, '\\', "]") + "]" + " = " + Util::escape(values.value(mapKey)) + "\n"; } return ret; break; @@ -36,13 +36,13 @@ QString ConfigBase::getConfigValueLine(const QString &name) QString ret; foreach(const QString& val, (dynamic_cast<ConfigValueList*>(&value))->getValues()) { - ret += name + " += " + val + "\n"; + ret += name + " += " + Util::escape(val) + "\n"; } return ret; break; } default: - return name + " = " + value.value() + "\n"; + return name + " = " + Util::escape(value.value()) + "\n"; } } else @@ -58,7 +58,7 @@ void ConfigBase::addConfigListEntry(const QString &name, const QString &value) { throw ConfigException("Cannot add a list entry to a non-list-config value \"" + name.toStdString() + "\""); } - ((ConfigValueList*)&configValue)->append(value); + ((ConfigValueList*)&configValue)->append(Util::unescape(value)); } void ConfigBase::removeConfigMapListEntry(const QString &name, const QString &value) @@ -66,11 +66,11 @@ void ConfigBase::removeConfigMapListEntry(const QString &name, const QString &va ConfigValueBase& configValue = getConfigValue(name); if(configValue.type() == ConfigValueType::List) { - ((ConfigValueList*)&configValue)->remove(value); + ((ConfigValueList*)&configValue)->remove(Util::unescape(value)); } else if(configValue.type() == ConfigValueType::Map) { - ((ConfigValueMap*)&configValue)->remove(value); + ((ConfigValueMap*)&configValue)->remove(Util::unescape(value)); } else { @@ -85,7 +85,7 @@ void ConfigBase::setConfigMapValue(const QString &name, const QString &key, cons { throw ConfigException("Cannot set a map value on a non-map-config value \"" + name.toStdString() + "\""); } - ((ConfigValueMap*)&configValue)->setKeyValue(key, value); + ((ConfigValueMap*)&configValue)->setKeyValue(Util::unescape(key), Util::unescape(value)); } ConfigValueBase& ConfigBase::getConfigValue(const QString& name) @@ -170,7 +170,7 @@ void ConfigBase::setConfigLine(const QString &line) static QRegExp valueExp(R"(^([^=]+)=(.*)$)"); static QRegExp listExp(R"(^([^=]+)\+=(.*)$)"); static QRegExp listMapRemoveExp(R"(^([^=]+)\-=(.*)$)"); - static QRegExp mapExp(R"(^([^\[]+)\[([^\]]+)\]\s*=\s*(.*)$)"); + static QRegExp mapExp(R"(^([^\[]+)\[((?:[^\]\\]|\\\]|\\\\)+)\]\s*=\s*(.*)$)"); if(listExp.exactMatch(line)) { |
