Can not add sources if url does not end with a slash #184

Closed
opened 2025-02-28 18:45:38 +00:00 by davidoskky · 8 comments
Contributor

Description

If you log in entering the url without a final slash, the login correctly works. However, the url is considered invalid when attempting to add sources.

Steps to Reproduce

  1. Log in introducing the url of the server without final slash
  2. Open the sources page
  3. Tap the + button

Expected behavior: You should be able to add sources anyway.

### Description If you log in entering the url without a final slash, the login correctly works. However, the url is considered invalid when attempting to add sources. ### Steps to Reproduce 1. Log in introducing the url of the server without final slash 2. Open the sources page 3. Tap the + button **Expected behavior:** You should be able to add sources anyway.
Owner

I couldn't reproduce. Are you sure the issue isn't with the selfoss api ?

I couldn't reproduce. Are you sure the issue isn't with the selfoss api ?
AmineB added the
Status = Need more details
label 2025-03-02 12:26:43 +00:00
Author
Contributor

Strange, I was able to reproduce this on my physical device and on emulated devices with API 25, 34 and 35.
I'm running Selfoss 2.19 stable, but I reckon I do not have a second instance running to test this on. No API call appears to take place, thus I'd exclude it is a problem on server side.

Looking here it appears that urls without a final slash should not even be allowed to log in at all:

fun String.isBaseUrlInvalid(): Boolean {
val baseUrl = this.toHttpUrlOrNull()
var existsAndEndsWithSlash = false
if (baseUrl != null) {
val pathSegments = baseUrl.pathSegments
existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1]
}
return !(Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash)
}

However, I am able to log in. When attempting to add a source I receive the error message "Log in to add sources." in a toast. The client has correctly done the login since I am able to use the application normally and my selfoss instance does not allow guest access.

Strange, I was able to reproduce this on my physical device and on emulated devices with API 25, 34 and 35. I'm running Selfoss 2.19 stable, but I reckon I do not have a second instance running to test this on. No API call appears to take place, thus I'd exclude it is a problem on server side. Looking here it appears that urls without a final slash should not even be allowed to log in at all: https://gitea.amine-bouabdallaoui.fr/Louvorg/ReaderForSelfoss-multiplatform/src/commit/f38936f9b43c099785c32ff83d5bbdfd64a78f33/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt#L48-L57 However, I am able to log in. When attempting to add a source I receive the error message "Log in to add sources." in a toast. The client has correctly done the login since I am able to use the application normally and my selfoss instance does not allow guest access.
Owner

this.toHttpUrlOrNull() returns the url with a slash.

Can you provide a screengrab of the error, please?

`this.toHttpUrlOrNull()` returns the url with a slash. Can you provide a screengrab of the error, please?
Author
Contributor

Here you go, right after tapping the button to add a source I am redirected to the home and the toast appears.

Here you go, right after tapping the button to add a source I am redirected to the home and the toast appears.
Owner

The isBaseUrlInvalid is called on the login screen, so the result should be the same on the sources screen too.

This isn't an issue with the url.

The `isBaseUrlInvalid` is called on the login screen, so the result should be the same on the sources screen too. This isn't an issue with the url.
Owner

I'll close for now. Please reopen if you have more details.

I'll close for now. Please reopen if you have more details.
Author
Contributor

So, I went through both checks with the debugger.
isBaseUrlInvalid does return true in both cases when you use a url without a final slash. However in the login process, that does not stop the login attempt. Login is successful and thus you proceed to the home page. In the source adding page, if the base url is considered invalid then it immediately kicks you out without attempting to perform any operation.

It is supposedly a bit strange, because this is the only place in the application where we check the validity of the url after we already did log in. I'm not really sure the check itself is necessary and may be removed altogether from the sources. I think the check is meant to ensure we actually did log in and are not connected as a guest, but that is not really what it is doing.
Alternatively we may stop considering as invalid urls who do not end with a slash, as these appear to be perfectly valid for all other operations.

So, I went through both checks with the debugger. `isBaseUrlInvalid` does return true in both cases when you use a url without a final slash. However in the login process, that does not stop the login attempt. Login is successful and thus you proceed to the home page. In the source adding page, if the base url is considered invalid then it immediately kicks you out without attempting to perform any operation. It is supposedly a bit strange, because this is the only place in the application where we check the validity of the url after we already did log in. I'm not really sure the check itself is necessary and may be removed altogether from the sources. I think the check is meant to ensure we actually did log in and are not connected as a guest, but that is not really what it is doing. Alternatively we may stop considering as invalid urls who do not end with a slash, as these appear to be perfectly valid for all other operations.
Owner

Thanks for the details. I fixed the issue.

Thanks for the details. I fixed the issue.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Louvorg/ReaderForSelfoss-multiplatform#184
No description provided.