Skip to content

Commit 26888c0

Browse files
committed
#1635 fix: do not crash if the URL for the HTTP action is malformed
1 parent 336012c commit 26888c0

7 files changed

Lines changed: 21 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
## [3.0 Beta 6](https://github.com/sds100/KeyMapper/releases/tag/v3.0.0-beta.6)
2+
3+
#### TO BE RELEASED
4+
5+
## Bug fixes
6+
7+
- #1635 do not crash if the URL for the HTTP action is malformed
8+
19
## [3.0 Beta 5](https://github.com/sds100/KeyMapper/releases/tag/v3.0.0-beta.5)
210

311
#### 6 April 2025
412

513
- #1625 HTTP Request action.
614

7-
###
8-
915
## Bug fixes
1016

1117
- #1627 open camera app action does not work when device is locked

app/src/main/java/io/github/sds100/keymapper/actions/CreateActionDelegate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class CreateActionDelegate(
777777
httpRequestBottomSheetState = ActionData.HttpRequest(
778778
description = "",
779779
method = HttpMethod.GET,
780-
url = "",
780+
url = "http://",
781781
body = "",
782782
authorizationHeader = "",
783783
)

app/src/main/java/io/github/sds100/keymapper/actions/HttpRequestBottomSheet.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import io.github.sds100.keymapper.system.network.HttpMethod
4343
import io.github.sds100.keymapper.util.ui.compose.KeyMapperDropdownMenu
4444
import kotlinx.coroutines.flow.update
4545
import kotlinx.coroutines.launch
46+
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
4647

4748
@OptIn(ExperimentalMaterial3Api::class)
4849
@Composable
@@ -106,6 +107,7 @@ private fun HttpRequestBottomSheet(
106107
val descriptionEmptyErrorString =
107108
stringResource(R.string.action_http_request_description_empty_error)
108109
val urlEmptyErrorString = stringResource(R.string.action_http_request_url_empty_error)
110+
val malformedUrlErrorString = stringResource(R.string.action_http_request_malformed_url_error)
109111

110112
var descriptionError: String? by rememberSaveable { mutableStateOf(null) }
111113
var urlError: String? by rememberSaveable { mutableStateOf(null) }
@@ -272,6 +274,10 @@ private fun HttpRequestBottomSheet(
272274
urlError = urlEmptyErrorString
273275
}
274276

277+
if (state.url.toHttpUrlOrNull() == null) {
278+
urlError = malformedUrlErrorString
279+
}
280+
275281
if (descriptionError == null && urlError == null) {
276282
onDoneClick()
277283
}

app/src/main/java/io/github/sds100/keymapper/system/network/AndroidNetworkAdapter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ class AndroidNetworkAdapter(
170170
} catch (e: IOException) {
171171
Timber.e(e)
172172
return Error.UnknownIOError
173+
} catch (e: IllegalArgumentException) {
174+
return Error.MalformedUrl
173175
}
174176
}
175177
}

app/src/main/java/io/github/sds100/keymapper/util/ErrorUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ fun Error.getFullMessage(resourceProvider: ResourceProvider): String = when (thi
161161
Error.PurchasingNotImplemented -> resourceProvider.getString(R.string.purchasing_error_not_implemented)
162162
Error.DpadTriggerImeNotSelected -> resourceProvider.getString(R.string.trigger_error_dpad_ime_not_selected)
163163
Error.InvalidBackup -> resourceProvider.getString(R.string.error_invalid_backup)
164+
Error.MalformedUrl -> resourceProvider.getString(R.string.error_malformed_url)
164165
}
165166

166167
val Error.isFixable: Boolean

app/src/main/java/io/github/sds100/keymapper/util/Result.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ sealed class Error : Result<Nothing>() {
144144
* DPAD triggers require a Key Mapper keyboard to be selected.
145145
*/
146146
data object DpadTriggerImeNotSelected : Error()
147+
data object MalformedUrl : Error()
147148
}
148149

149150
inline fun <T> Result<T>.onSuccess(f: (T) -> Unit): Result<T> {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@
885885
<string name="error_no_file_name">This file has no name!</string>
886886
<string name="error_invalid_backup">Invalid file. Must be a zip exported from Key Mapper.</string>
887887
<string name="error_choose_bluetooth_devices_permission_denied">You must grant Key Mapper permission to see your paired Bluetooth devices.</string>
888+
<string name="error_malformed_url">Malformed URL. Did you forget the http://?</string>
888889

889890
<string name="error_access_fine_location_permission_denied">Denied permission to read fine location!</string>
890891
<string name="error_answer_end_phone_call_permission_denied">Denied permission to answer and end phone calls!</string>
@@ -1083,6 +1084,7 @@
10831084
<string name="action_http_request_description_empty_error">Can not be empty!</string>
10841085
<string name="action_http_request_url_label">URL</string>
10851086
<string name="action_http_request_url_empty_error">Can not be empty!</string>
1087+
<string name="action_http_request_malformed_url_error">Malformed URL. Did you forget the http://?</string>
10861088
<string name="action_http_request_body_label">Request body (optional)</string>
10871089
<string name="action_http_request_authorization_label">Authorization header (optional)</string>
10881090
<string name="action_http_request_authorization_supporting_text">You must prepend \'Bearer\' if necessary</string>

0 commit comments

Comments
 (0)