File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed
kotlin/src/main/kotlin/io/appwrite Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import java.io.RandomAccessFile
23
23
import java.io.IOException
24
24
import java.security.SecureRandom
25
25
import java.security.cert.X509Certificate
26
+ import java.net.URL
26
27
import javax.net.ssl.HostnameVerifier
27
28
import javax.net.ssl.SSLContext
28
29
import javax.net.ssl.SSLSocketFactory
@@ -152,7 +153,12 @@ class Client @JvmOverloads constructor(
152
153
*
153
154
* @return this
154
155
*/
156
+ @Throws({{ spec .title | caseUcfirst }}Exception::class)
155
157
fun setEndpoint(endPoint: String): Client {
158
+ if (runCatching { URL(endpoint).protocol !in listOf("http", "https") }.getOrDefault(false)) {
159
+ throw {{spec .title | caseUcfirst }}Exception("Invalid endpoint URL: $endpoint")
160
+ }
161
+
156
162
this.endPoint = endPoint
157
163
return this
158
164
}
Original file line number Diff line number Diff line change @@ -92,8 +92,12 @@ class Client
92
92
*/
93
93
public function setEndpoint (string $endpoint ): Client
94
94
{
95
- $this -> endpoint = $endpoint ;
95
+ $scheme = parse_url ($endpoint , PHP_URL_SCHEME );
96
+ if ($scheme ! == ' http' && $scheme ! == ' https' ) {
97
+ throw new {{spec . title | caseUcfirst }}Exception(" Invalid endpoint URL: $endpoint " );
98
+ }
96
99
100
+ $this -> endpoint = $endpoint ;
97
101
return $this ;
98
102
}
99
103
Original file line number Diff line number Diff line change @@ -31,8 +31,12 @@ class Tests: XCTestCase {
31
31
print ( pingResult)
32
32
33
33
// reset configs
34
- client. setProject ( " console " )
35
- . setEndpointRealtime ( " ws://cloud.appwrite.io/v1 " )
34
+ try {
35
+ client. setProject ( " console " )
36
+ . setEndpointRealtime ( " ws://cloud.appwrite.io/v1 " )
37
+ } catch {
38
+ print ( error. localizedDescription)
39
+ }
36
40
37
41
let foo = Foo ( client)
38
42
let bar = Bar ( client)
You can’t perform that action at this time.
0 commit comments