Skip to content

Commit

Permalink
Fix faulty URL handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johboh committed Mar 26, 2023
1 parent ce3651d commit 5d5f612
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.fjun.hassalarm"
minSdkVersion 23
targetSdkVersion 33
versionCode 24
versionName "1.24"
versionCode 25
versionName "1.25"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/fjun/hassalarm/NextAlarmUpdaterJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.fjun.hassalarm.history.AppDatabase.Companion.getDatabase
import com.fjun.hassalarm.history.Publish
import com.fjun.hassalarm.history.PublishDao
import java.io.IOException
import java.net.URI
import java.text.SimpleDateFormat
import java.util.*
import okhttp3.ResponseBody
Expand Down Expand Up @@ -178,11 +179,13 @@ class NextAlarmUpdaterJob : JobService() {
// Verify host and API key.
require(hostInput.isNotEmpty()) { "Host is missing. You need to specify the host to your hass.io instance." }

// No port number? Add default one.
val hostToUse = when {
!hostInput.contains(":") -> "$hostInput:$DEFAULT_PORT"
!hostInput.startsWith("http://") && !hostInput.startsWith("https://") -> "http://$hostInput"
else -> hostInput
var hostToUse = hostInput
if (!hostToUse.startsWith("http://") && !hostToUse.startsWith("https://")) {
hostToUse = "http://$hostToUse"
}
val uri = URI(hostToUse)
if (uri.port == -1) {
hostToUse = "$hostToUse:$DEFAULT_PORT"
}

// Support empty API key, if there is no one required.
Expand Down

0 comments on commit 5d5f612

Please sign in to comment.