Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .netrc parsing #7698

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/cmd/netrcparser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/cmd/netrcparser.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/cmd/netrcparser.cpp

File src/cmd/netrcparser.cpp does not conform to Custom style guidelines. (lines 68)
* Copyright (C) by Daniel Molkentin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -12,10 +12,9 @@
* for more details.
*/

#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 @@ -57,33 +56,37 @@
return false;
}
QString content = netrc.readAll();
if (content.isEmpty()) {
return false;
}

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;
break;
}
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
3 changes: 1 addition & 2 deletions test/testnetrcparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* any purpose.
* */

#include <QtTest>

Check failure on line 7 in test/testnetrcparser.cpp

View workflow job for this annotation

GitHub Actions / build

test/testnetrcparser.cpp:7:10 [clang-diagnostic-error]

'QtTest' file not found

#include "cmd/netrcparser.h"
#include "logger.h"
Expand Down Expand Up @@ -53,11 +53,11 @@

void testValidNetrc() {
NetrcParser parser(testfileC);
QEXPECT_FAIL("", "test currently broken, eventually will be fixed", Abort);
QVERIFY(parser.parse());
QCOMPARE(parser.find("foo"), qMakePair(QString("bar"), QString("baz")));
QCOMPARE(parser.find("broken"), qMakePair(QString("bar2"), QString()));
QCOMPARE(parser.find("funnysplit"), qMakePair(QString("bar3"), QString("baz3")));
QEXPECT_FAIL("", "Current implementation do not support spaces in username or password", Continue);
QCOMPARE(parser.find("frob"), qMakePair(QString("user with spaces"), QString("space pwd")));
}

Expand All @@ -69,7 +69,6 @@

void testValidNetrcWithDefault() {
NetrcParser parser(testfileWithDefaultC);
QEXPECT_FAIL("", "test currently broken, eventually will be fixed", Abort);
QVERIFY(parser.parse());
QCOMPARE(parser.find("foo"), qMakePair(QString("bar"), QString("baz")));
QCOMPARE(parser.find("dontknow"), qMakePair(QString("user"), QString("pass")));
Expand Down
Loading