Skip to content

Commit

Permalink
Fix parsing package data and incomplete package-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Jan 10, 2018
1 parent be3472b commit da8db19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 64 deletions.
52 changes: 4 additions & 48 deletions src/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,66 +226,22 @@ uint Daemon::versionMicro()

QString Daemon::packageName(const QString &packageID)
{
QString ret;
ret = packageID.left(packageID.indexOf(QLatin1Char(';')));
return ret;
return Transaction::packageName(packageID);
}

QString Daemon::packageVersion(const QString &packageID)
{
QString ret;
int start = packageID.indexOf(QLatin1Char(';')) + 1;
if (start == -1) {
return ret;
}
int end = packageID.indexOf(QLatin1Char(';'), start);
if (end == -1) {
return ret;
}
ret = packageID.mid(start, end - start);
return ret;
return Transaction::packageVersion(packageID);
}

QString Daemon::packageArch(const QString &packageID)
{
QString ret;
int start = packageID.indexOf(QLatin1Char(';')) + 1;
if (start == -1) {
return ret;
}
start = packageID.indexOf(QLatin1Char(';'), start) + 1;
if (start == -1) {
return ret;
}
int end = packageID.indexOf(QLatin1Char(';'), start);
if (end == -1) {
return ret;
}
ret = packageID.mid(start, end - start);
return ret;
return Transaction::packageArch(packageID);
}

QString Daemon::packageData(const QString &packageID)
{
QString ret;
int start = packageID.indexOf(QLatin1Char(';')) + 1;
if (start == -1) {
return ret;
}
start = packageID.indexOf(QLatin1Char(';'), start) + 1;
if (start == -1) {
return ret;
}
start = packageID.indexOf(QLatin1Char(';'), start) + 1;
if (start == -1) {
return ret;
}
int end = packageID.indexOf(QLatin1Char(';'), start);
if (end == -1) {
return ret;
}
ret = packageID.mid(start, end - start);
return ret;
return Transaction::packageData(packageID);
}

Transaction *Daemon::acceptEula(const QString &eulaId)
Expand Down
31 changes: 15 additions & 16 deletions src/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ QString Transaction::packageVersion(const QString &packageID)
if (start == -1) {
return ret;
}
int end = packageID.indexOf(QLatin1Char(';'), start);
if (end == -1) {
return ret;
int end = packageID.indexOf(QLatin1Char(';'), ++start);
if (Q_UNLIKELY(end == -1)) {
ret = packageID.mid(start);
} else {
ret = packageID.mid(start, end - start);
}
ret = packageID.mid(start, end - start);
return ret;
}

Expand All @@ -209,15 +210,16 @@ QString Transaction::packageArch(const QString &packageID)
if (start == -1) {
return ret;
}
start = packageID.indexOf(QLatin1Char(';'), start);
start = packageID.indexOf(QLatin1Char(';'), ++start);
if (start == -1) {
return ret;
}
int end = packageID.indexOf(QLatin1Char(';'), start);
if (end == -1) {
return ret;
int end = packageID.indexOf(QLatin1Char(';'), ++start);
if (Q_UNLIKELY(end == -1)) {
ret = packageID.mid(start);
} else {
ret = packageID.mid(start, end - start);
}
ret = packageID.mid(start, end - start);
return ret;
}

Expand All @@ -228,19 +230,16 @@ QString Transaction::packageData(const QString &packageID)
if (start == -1) {
return ret;
}
start = packageID.indexOf(QLatin1Char(';'), start);
start = packageID.indexOf(QLatin1Char(';'), ++start);
if (start == -1) {
return ret;
}
start = packageID.indexOf(QLatin1Char(';'), start);
start = packageID.indexOf(QLatin1Char(';'), ++start);
if (start == -1) {
return ret;
}
int end = packageID.indexOf(QLatin1Char(';'), start);
if (end == -1) {
return ret;
}
ret = packageID.mid(start, end - start);

ret = packageID.mid(++start);
return ret;
}

Expand Down

0 comments on commit da8db19

Please sign in to comment.