Skip to content

Commit 591b404

Browse files
fredrik-erikssonmgallien
authored andcommitted
Fix .netrc parsing
Fixes: #7177 Signed-off-by: Fredrik Eriksson <[email protected]>
1 parent 1441c89 commit 591b404

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/cmd/netrcparser.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
#include <QDir>
1616
#include <QFile>
17-
#include <QTextStream>
18-
#include <QStringTokenizer>
17+
#include <QRegularExpression>
1918

2019
#include <QDebug>
2120

@@ -58,32 +57,33 @@ bool NetrcParser::parse()
5857
}
5958
QString content = netrc.readAll();
6059

61-
auto tokenizer = QStringTokenizer{content, u" \n\t"};
60+
auto tokens = content.split(QRegularExpression("\\s+"));
6261

6362
LoginPair pair;
6463
QString machine;
6564
bool isDefault = false;
66-
for(auto itToken = tokenizer.cbegin(); itToken != tokenizer.cend(); ++itToken) {
67-
const auto key = *itToken;
65+
for(int i=0; i<tokens.count(); i++) {
66+
const auto key = tokens[i];
6867
if (key == defaultKeyword) {
6968
tryAddEntryAndClear(machine, pair, isDefault);
7069
isDefault = true;
7170
continue; // don't read a value
7271
}
7372

74-
if (itToken != tokenizer.cend()) {
73+
i++;
74+
if (i > tokens.count()) {
7575
qDebug() << "error fetching value for" << key;
7676
return false;
7777
}
78-
auto value = *(++itToken);
78+
auto value = tokens[i];
7979

8080
if (key == machineKeyword) {
8181
tryAddEntryAndClear(machine, pair, isDefault);
82-
machine = value.toString();
82+
machine = value;
8383
} else if (key == loginKeyword) {
84-
pair.first = value.toString();
84+
pair.first = value;
8585
} else if (key == passwordKeyword) {
86-
pair.second = value.toString();
86+
pair.second = value;
8787
} // ignore unsupported tokens
8888
}
8989
tryAddEntryAndClear(machine, pair, isDefault);

0 commit comments

Comments
 (0)