Skip to content

Commit

Permalink
User can not input illegal symbols in custom headers
Browse files Browse the repository at this point in the history
  • Loading branch information
GrakovNe committed Dec 2, 2024
1 parent d140fd9 commit d343522
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId = "org.grakovne.lissen"
minSdk = 28
targetSdk = 35
versionCode = 46
versionName = "1.1.15"
versionCode = 47
versionName = "1.1.16"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ data class ServerRequestHeader(
return this.copy(name = name, value = value)
}

private fun String.clean(): String {
var sanitized = this.replace(Regex("[\\r\\n]"), "")
sanitized = sanitized.replace(Regex("[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"), "")
sanitized = sanitized.trim()

return sanitized
}
private fun String.clean(): String = this.replace(Regex("[^a-zA-Z0-9-]"), "").trim()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.grakovne.lissen.R
import org.grakovne.lissen.domain.connection.ServerRequestHeader
import org.grakovne.lissen.domain.connection.ServerRequestHeader.Companion.clean

@Composable
fun CustomHeaderComposable(
Expand All @@ -46,7 +47,7 @@ fun CustomHeaderComposable(
) {
OutlinedTextField(
value = header.name,
onValueChange = { onChanged(header.copy(name = it, value = header.value)) },
onValueChange = { onChanged(header.copy(name = it, value = header.value).clean()) },
label = { Text(stringResource(R.string.custom_header_hint_name)) },
singleLine = true,
shape = RoundedCornerShape(16.dp),
Expand All @@ -55,7 +56,7 @@ fun CustomHeaderComposable(

OutlinedTextField(
value = header.value,
onValueChange = { onChanged(header.copy(name = header.name, value = it)) },
onValueChange = { onChanged(header.copy(name = header.name, value = it).clean()) },
label = { Text(stringResource(R.string.custom_header_hint_value)) },
singleLine = true,
shape = RoundedCornerShape(16.dp),
Expand Down

0 comments on commit d343522

Please sign in to comment.