Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 8a97897

Browse files
committed
Use QSS to validate uri. Fix #682
1 parent 1bd3494 commit 8a97897

File tree

2 files changed

+8
-38
lines changed

2 files changed

+8
-38
lines changed

src/ssvalidator.cpp

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,15 @@ QStringList SSValidator::supportedMethodList()
1212
return methodList;
1313
}
1414

15-
bool SSValidator::validate(QString input)
15+
bool SSValidator::validate(const QString &input)
1616
{
17-
//must begin with ss:// to distinguish from random base64 encoded strings
18-
if (input.startsWith("ss://")) {
19-
input.remove(0, 5);
20-
QStringList tagList = input.split('#');
21-
QString decode(QByteArray::fromBase64(tagList.first().toUtf8()));
22-
QStringList decList = decode.split(':');
23-
if (decList.size() < 3) {
24-
return false;
25-
}
26-
27-
//Validate Method
28-
QString method = decList.first().toUpper();
29-
if (method.endsWith("-AUTH")) {
30-
method.remove("-AUTH");
31-
}
32-
if (!validateMethod(method)) {
33-
return false;
34-
}
35-
36-
//Validate Port
37-
QString port = decList.last();
38-
if (!validatePort(port)) {
39-
return false;
40-
}
41-
42-
//Validate whether server and password exist
43-
QStringList pwdServer = decList.at(1).split('@');
44-
if (pwdServer.size() < 2) {
45-
return false;
46-
}
47-
48-
//it seems acceptable now
49-
return true;
50-
}
51-
else {
52-
return false;
17+
bool valid = true;
18+
try {
19+
QSS::Profile::fromUri(input.toStdString());
20+
} catch(const std::exception&) {
21+
valid = false;
5322
}
23+
return valid;
5424
}
5525

5626
bool SSValidator::validatePort(const QString &port)

src/ssvalidator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class SSValidator
2525
{
2626
public:
27-
static bool validate(QString input);
27+
static bool validate(const QString &input);
2828
static bool validatePort(const QString &port);
2929
static bool validateMethod(const QString &method);
3030

0 commit comments

Comments
 (0)