Skip to content

Commit a2c55f0

Browse files
committed
chore: add check to kotlin and php
1 parent 9da4bcb commit a2c55f0

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import java.io.RandomAccessFile
2323
import java.io.IOException
2424
import java.security.SecureRandom
2525
import java.security.cert.X509Certificate
26+
import java.net.URL
2627
import javax.net.ssl.HostnameVerifier
2728
import javax.net.ssl.SSLContext
2829
import javax.net.ssl.SSLSocketFactory
@@ -152,7 +153,12 @@ class Client @JvmOverloads constructor(
152153
*
153154
* @return this
154155
*/
156+
@Throws({{ spec.title | caseUcfirst }}Exception::class)
155157
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+
156162
this.endPoint = endPoint
157163
return this
158164
}

templates/php/src/Client.php.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ class Client
9292
*/
9393
public function setEndpoint(string $endpoint): Client
9494
{
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+
}
9699
100+
$this->endpoint = $endpoint;
97101
return $this;
98102
}
99103

tests/languages/apple/Tests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ class Tests: XCTestCase {
3131
print(pingResult)
3232

3333
// 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+
}
3640

3741
let foo = Foo(client)
3842
let bar = Bar(client)

0 commit comments

Comments
 (0)