Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLs redirected by LibRedirect never loads #121

Closed
LightWayUp opened this issue Jun 14, 2023 · 1 comment
Closed

URLs redirected by LibRedirect never loads #121

LightWayUp opened this issue Jun 14, 2023 · 1 comment
Assignees
Labels

Comments

@LightWayUp
Copy link

Bug description

If LibRedirect is enabled, URLs that are redirected is never loaded, "Loading link..." never completes.

In the current nightly, HTTPS scheme is to be stripped from instances' URLs when they're displayed. However, cleanHttpsScheme() is instead applied to the loaded URLs directly, and then saved as-is into the database upon user selection. Because the saved instanceUrl now lacks a scheme, when LibRedirectResolver calls Uri.parse() with the redirected URL, a malformed Uri is created, and subsequent usages of it hangs. (Invalid input doesn't lead to an exception due to performance concerns)

Hot fix 🔥
--- /app/src/main/java/fe/linksheet/module/viewmodel/LibRedirectServiceSettingsViewModel.kt    aed6676434b796b90d3f40ca9e51633fd5407de1
+++ /app/src/main/java/fe/linksheet/module/viewmodel/LibRedirectServiceSettingsViewModel.kt    HEAD
@@ -80,5 +80,3 @@
    val instances = builtinInstances.combine(selectedFrontend) { instances, selected ->
-        instances.find { it.frontendKey == selected?.key }?.hosts?.map { host ->
-            cleanHttpsScheme(host)
-        }?.sorted()
+        instances.find { it.frontendKey == selected?.key }?.hosts?.sorted()
    }

--- /app/src/main/java/fe/linksheet/composable/settings/link/libredirect/LibRedirectSettingsRoute.kt    aed6676434b796b90d3f40ca9e51633fd5407de1
+++ /app/src/main/java/fe/linksheet/composable/settings/link/libredirect/LibRedirectSettingsRoute.kt    HEAD
@@ -115,6 +115,6 @@
@Composable
private fun instanceUrl(
    instance: String
) = if (instance == LibRedirectDefault.libRedirectRandomInstanceKey) stringResource(
    id = R.string.random_instance
-) else instance
+) else cleanHttpsScheme(instance)

--- /app/src/main/java/fe/linksheet/composable/settings/link/libredirect/LibRedirectServiceSettingsRoute.kt    aed6676434b796b90d3f40ca9e51633fd5407de1
+++ /app/src/main/java/fe/linksheet/composable/settings/link/libredirect/LibRedirectServiceSettingsRoute.kt    HEAD
@@ -47,0 +47,1 @@
+import fe.linksheet.util.cleanHttpsScheme
@@ -162,9 +163,9 @@
                    items(items = instances!!, key = { it }) { instance ->
                        InstanceItem(
                            enabled = enabled!!,
-                            text = instance,
+                            text = cleanHttpsScheme(instance),
                            instance = instance,
                            selectedInstance = selectedInstance,
                            itemOnClick = itemOnClick
                        )
                    }

Version

Nightly

Previous version

0.0.31

Device

Android Emulator

Android version

Android 13

Application log or crash log

With LibRedirect disabled:

1685271000000 D x: Intent=act=android.intent.action.VIEW,cmp=ComponentInfo{fe.linksheet.nightly/fe.linksheet.activity.BottomSheetActivity},flags=276824064
1685271000004 D c: GetUri: Pre modification=https://twitter.com/Twitter
1685271000011 D c: GetUri: Post FastForward=https://twitter.com/Twitter
1685271000011 D c: GetUri: Post ClearURL=https://twitter.com/Twitter
1685271000078 D x: PreferredApp=
1685271000100 D x: LastUsedApps=
1685271000102 D x: NewIntent=act=android.intent.action.VIEW,flags=268435456
1685271000107 D x: ResolveList=[ResolveInfo{bbb35fa com.android.chrome/com.google.android.apps.chrome.IntentDispatcher m=0x208000}]
1685271000117 D x: BrowserMode=mode=always_ask
1685271000178 D x: Grouped=[activityInfo=ActivityInfo{6977edd com.google.android.apps.chrome.IntentDispatcher},label=Chrome,resolveInfo=ResolveInfo{bbb35fa com.android.chrome/com.google.android.apps.chrome.IntentDispatcher m=0x208000}], filteredItem=, showExtended=false, selectedBrowserIsSingleOption=false, noBrowsersPresentOnlySingleApp=false
1685271010884 D i: Component=ComponentInfo{com.android.chrome/com.google.android.apps.chrome.IntentDispatcher}
1685271010927 D i: Inserting=host=twitter.com,pkg=com.android.chrome,cmp=ComponentInfo{com.android.chrome/com.google.android.apps.chrome.IntentDispatcher},alwaysPreferred=false
1685271011017 D i: Inserting={host=twitter.com,packageName=com.android.chrome,lastUsed=1685271010975}

With LibRedirect enabled:

1685271120000 D x: Intent=act=android.intent.action.VIEW,cmp=ComponentInfo{fe.linksheet.nightly/fe.linksheet.activity.BottomSheetActivity},flags=276824064
1685271120004 D c: GetUri: Pre modification=https://twitter.com/Twitter
1685271120005 D c: GetUri: Post FastForward=https://twitter.com/Twitter
1685271120013 D c: GetUri: Post ClearURL=https://twitter.com/Twitter
1685271120088 D c0: Service=twitter
1685271120177 D c0: Redirected=nitter.net/Twitter#m

Reproducible on latest nightly build

Yes

@1fexd
Copy link
Collaborator

1fexd commented Jun 15, 2023

Thanks! You are very welcome to open a PR with your fix!

1fexd added a commit that referenced this issue Jun 15, 2023
@1fexd 1fexd closed this as completed Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants