Skip to content

Commit

Permalink
Fix: force load config reports success with invalid URLs (#4621)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1204912272578138/1207434405087911/f

### Description
Ditto

### Steps to test this PR
- [x] Go to Developer Settings --> Override Privacy Remote Config URL
- [x] Enable custom config
- [x] Type in an invalid URL e.g., `http://example.com:3000:3000/config`
- [x] "Force load config" should be disabled
  • Loading branch information
nshuba authored Jun 7, 2024
1 parent 53af198 commit 8e2704b
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.duckduckgo.privacy.config.internal.PrivacyConfigInternalViewModel.Com
import com.duckduckgo.privacy.config.internal.store.DevPrivacyConfigSettingsDataStore
import com.duckduckgo.privacy.config.store.PrivacyConfig
import com.duckduckgo.privacy.config.store.PrivacyConfigRepository
import java.net.URI
import javax.inject.Inject
import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST
import kotlinx.coroutines.channels.Channel
Expand Down Expand Up @@ -98,7 +99,8 @@ class PrivacyConfigInternalViewModel @Inject constructor(
fun canUrlBeChanged(): Boolean {
val storedUrl = store.remotePrivacyConfigUrl
val isCustomSettingEnabled = store.useCustomPrivacyConfigUrl
val canBeChanged = isCustomSettingEnabled && !storedUrl.isNullOrEmpty() && URLUtil.isValidUrl(storedUrl)
val validHost = runCatching { URI(storedUrl).host.isNotEmpty() }.getOrDefault(false)
val canBeChanged = isCustomSettingEnabled && !storedUrl.isNullOrEmpty() && URLUtil.isValidUrl(storedUrl) && validHost
store.canUrlBeChanged = canBeChanged
return canBeChanged
}
Expand Down

0 comments on commit 8e2704b

Please sign in to comment.