Config reading fix

master
const an teen 2021-12-04 11:41:39 -05:00
parent 0f2aad299b
commit ddc074c0e4
1 changed files with 6 additions and 6 deletions

View File

@ -44,10 +44,10 @@ void ApplicationData::createConfigExample(const QString &pathToConfig)
"# triggers splitting by '<!>'\n" "# triggers splitting by '<!>'\n"
"triggers = request = hi ::: answer = hello <!> request=developer:::answer=acetone\n\n" "triggers = request = hi ::: answer = hello <!> request=developer:::answer=acetone\n\n"
"# Optional parameters if global is defined:\n" "# Optional parameters if global is defined:\n"
"nick = unique_nickname_for_this_server\n" "#nick = unique_nickname_for_this_server\n"
"user = unique_ident_for_this_server\n" "#user = unique_ident_for_this_server\n"
"real_name = unique_real_name_for_this_server\n" "#real_name = unique_real_name_for_this_server\n"
"password = password_for_this_user\n" "#password = password_for_this_user\n"
}; };
file.write(configExample.toUtf8()); file.write(configExample.toUtf8());
@ -124,7 +124,7 @@ void ApplicationData::readConfig()
if (globalBegin == -1) { if (globalBegin == -1) {
throw std::runtime_error("ApplicationData::readConfig(): Wrong config. [GLOBAL] section not exist!"); throw std::runtime_error("ApplicationData::readConfig(): Wrong config. [GLOBAL] section not exist!");
} }
int globalEnd = conffile.indexOf('[', globalBegin+1); int globalEnd = conffile.indexOf(QRegularExpression("\\[[^:]*\\]"), globalBegin+1); //IPv6 addresses safe
if (globalEnd != -1) { if (globalEnd != -1) {
// Удаление последующей [секции] // Удаление последующей [секции]
globalSection.remove(globalEnd, conffile.size()-globalEnd); globalSection.remove(globalEnd, conffile.size()-globalEnd);
@ -193,7 +193,7 @@ void ApplicationData::readConfig()
while (conffile.contains(QRegularExpression("\\[[^\\n]*\\]"))) { while (conffile.contains(QRegularExpression("\\[[^\\n]*\\]"))) {
QString currentSection {conffile}; QString currentSection {conffile};
int begin = conffile.indexOf(QRegularExpression("\\[[^\\n]*\\]")); int begin = conffile.indexOf(QRegularExpression("\\[[^\\n]*\\]"));
int end = conffile.indexOf('[', begin+1); int end = conffile.indexOf(QRegularExpression("\\[[^:]*\\]"), begin+1);
if (end != -1) { if (end != -1) {
currentSection.remove(end, currentSection.size() - end); currentSection.remove(end, currentSection.size() - end);
} }