This repository was archived by the owner on Dec 10, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-38
lines changed Expand file tree Collapse file tree 2 files changed +8
-38
lines changed Original file line number Diff line number Diff line change @@ -12,45 +12,15 @@ QStringList SSValidator::supportedMethodList()
12
12
return methodList;
13
13
}
14
14
15
- bool SSValidator::validate (QString input)
15
+ bool SSValidator::validate (const QString & input)
16
16
{
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 ;
53
22
}
23
+ return valid;
54
24
}
55
25
56
26
bool SSValidator::validatePort (const QString &port)
Original file line number Diff line number Diff line change 24
24
class SSValidator
25
25
{
26
26
public:
27
- static bool validate (QString input);
27
+ static bool validate (const QString & input);
28
28
static bool validatePort (const QString &port);
29
29
static bool validateMethod (const QString &method);
30
30
You can’t perform that action at this time.
0 commit comments