Skip to content

Commit

Permalink
Fix .netrc parsing
Browse files Browse the repository at this point in the history
Fixes: #7177
Signed-off-by: Fredrik Eriksson <[email protected]>
  • Loading branch information
fredrik-eriksson authored and mgallien committed Jan 2, 2025
1 parent 1441c89 commit 591b404
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/cmd/netrcparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

#include <QDir>

Check failure on line 15 in src/cmd/netrcparser.cpp

View workflow job for this annotation

GitHub Actions / build

src/cmd/netrcparser.cpp:15:10 [clang-diagnostic-error]

'QDir' file not found
#include <QFile>
#include <QTextStream>
#include <QStringTokenizer>
#include <QRegularExpression>

#include <QDebug>

Expand Down Expand Up @@ -58,32 +57,33 @@ bool NetrcParser::parse()
}
QString content = netrc.readAll();

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

LoginPair pair;
QString machine;
bool isDefault = false;
for(auto itToken = tokenizer.cbegin(); itToken != tokenizer.cend(); ++itToken) {
const auto key = *itToken;
for(int i=0; i<tokens.count(); i++) {
const auto key = tokens[i];
if (key == defaultKeyword) {
tryAddEntryAndClear(machine, pair, isDefault);
isDefault = true;
continue; // don't read a value
}

if (itToken != tokenizer.cend()) {
i++;
if (i > tokens.count()) {
qDebug() << "error fetching value for" << key;
return false;
}
auto value = *(++itToken);
auto value = tokens[i];

if (key == machineKeyword) {
tryAddEntryAndClear(machine, pair, isDefault);
machine = value.toString();
machine = value;
} else if (key == loginKeyword) {
pair.first = value.toString();
pair.first = value;
} else if (key == passwordKeyword) {
pair.second = value.toString();
pair.second = value;
} // ignore unsupported tokens
}
tryAddEntryAndClear(machine, pair, isDefault);
Expand Down

0 comments on commit 591b404

Please sign in to comment.