diff --git a/src/cmd/netrcparser.cpp b/src/cmd/netrcparser.cpp index 266fe4f3e29fa..f9b95c762f614 100644 --- a/src/cmd/netrcparser.cpp +++ b/src/cmd/netrcparser.cpp @@ -14,8 +14,7 @@ #include #include -#include -#include +#include #include @@ -57,33 +56,37 @@ bool NetrcParser::parse() 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()) { 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); 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")));