From 212374b2ab30a9c9aa0adea8c02d72edf32619e0 Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Sat, 28 Dec 2024 12:34:12 +0100 Subject: [PATCH 1/3] Fix .netrc parsing Fixes: #7177 Signed-off-by: Fredrik Eriksson --- src/cmd/netrcparser.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cmd/netrcparser.cpp b/src/cmd/netrcparser.cpp index 266fe4f3e29fa..15417e1343883 100644 --- a/src/cmd/netrcparser.cpp +++ b/src/cmd/netrcparser.cpp @@ -14,8 +14,7 @@ #include #include -#include -#include +#include #include @@ -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()) { 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); From 5c0d095903b3f96709e95fb3fddcff156cd6e516 Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Thu, 2 Jan 2025 14:46:32 +0100 Subject: [PATCH 2/3] Fix index check Also fixes handling of empty netrc. Signed-off-by: Fredrik Eriksson --- src/cmd/netrcparser.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cmd/netrcparser.cpp b/src/cmd/netrcparser.cpp index 15417e1343883..f9b95c762f614 100644 --- a/src/cmd/netrcparser.cpp +++ b/src/cmd/netrcparser.cpp @@ -56,6 +56,9 @@ bool NetrcParser::parse() return false; } QString content = netrc.readAll(); + if (content.isEmpty()) { + return false; + } auto tokens = content.split(QRegularExpression("\\s+")); @@ -71,9 +74,9 @@ bool NetrcParser::parse() } i++; - if (i > tokens.count()) { + if (i >= tokens.count()) { qDebug() << "error fetching value for" << key; - return false; + break; } auto value = tokens[i]; From f1590663a5dea3251c24f37d9710ba9e1bf5eb24 Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Thu, 2 Jan 2025 14:59:18 +0100 Subject: [PATCH 3/3] Enable netrc tests Test for spaces in usernames and passwords is disabled for now as it's not supported by current implementation. Signed-off-by: Fredrik Eriksson --- test/testnetrcparser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/testnetrcparser.cpp b/test/testnetrcparser.cpp index f826edd8db536..3ab42698dcc2d 100644 --- a/test/testnetrcparser.cpp +++ b/test/testnetrcparser.cpp @@ -53,11 +53,11 @@ private slots: 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"))); } @@ -69,7 +69,6 @@ private slots: 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")));