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()
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
5626bool SSValidator::validatePort (const QString &port)
Original file line number Diff line number Diff line change 2424class SSValidator
2525{
2626public:
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
You can’t perform that action at this time.
0 commit comments